如何创建:分屏(1/2)

学习如何使用 CSS 创建分屏(50/50)效果。

Try it yourself

如何创建分屏

第一步 - 添加 HTML:

Avatar woman

Jane Flex

Some text.

Avatar man

Bill Gates

Some text here too.

第二步 - 添加 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%;
{}

Try it yourself