将屏幕分为两部分,宽度不同

时间:2019-02-23 08:24:00

标签: css html5

我正在尝试将页面分为两部分,但是大小不同。 使用以下代码,我得到了2个部分,但是大小相同。

http://jsfiddle.net/aL78z6kf/

html部分是:

<div class="split left">
  <div class="centered">
      <h2>Jane Flex</h2>
    <p>Some text.</p>
  </div>
</div>

<div class="split right">
  <div class="centered">
    <h2>John Doe</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;
}

/* Control the left side */
.left {
  left: 0;
  background-color: orange;
}

/* Control the right side */
.right {
  right: 0;
  background-color: red;
}

/* If you want the content centered horizontally and vertically */
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

/* Style the image inside the centered container, if needed */
.centered img {
  width: 150px;
  border-radius: 50%;
}

有可能吗? 预先感谢

1 个答案:

答案 0 :(得分:1)

JsFiddle

width:50%类中删除.split。并向.left.right类添加宽度属性(无论您想要什么)。

/* Control the left side */
.left {
  left: 0;
  background-color: orange;
  width: 30%;
}

/* Control the right side */
.right {
  right: 0;
  background-color: red;
  width: 70%;
}
相关问题