如何创建:分屏(1/2)
学习如何使用 CSS 创建分屏(50/50)效果。
如何创建分屏
第一步 - 添加 HTML:
<div class="split left"> <div class="centered"> <img src="img_avatar2.png" alt="Avatar woman"> <h2>Jane Flex</h2> <p>Some text.</p> </div> </div> <div class="split right"> <div class="centered"> <img src="img_avatar.png" alt="Avatar man"> <h2>Bill Gates</h2> <p>Some text here too.</p> </div> </div>
第二步 - 添加 CSS:
/* 将屏幕一分为二 */ .split { height: 100%; width: 50%; position: fixed; z-index: 1; top: 0; overflow-x: hidden; padding-top: 20px; } /* 控制左侧 */ .left { left: 0; background-color: #111; } /* 控制右侧 */ .right { right: 0; background-color: red; } /* 如果您想让内容在水平和垂直方向上都居中 */ .centered { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; } /* 如果需要,设置居中容器内的图片样式 */ .centered img { width: 150px; border-radius: 50%; }