css - 将屏幕分成两部分,宽度不同

标签 css html

我正在尝试将页面分成两部分,但大小不同。 使用以下代码,我得到 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%;
}

可以吗? 提前致谢

最佳答案

JsFiddle

.split 类中删除 width:50%。并将宽度属性(无论你想要什么)添加到 .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%;
}

关于css - 将屏幕分成两部分,宽度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54839636/

相关文章:

css - ExtJs 3。: How to add borders for the grid body cells(without gird header)

javascript - 我们可以在不使用 "onunload"的情况下捕获相同的浏览器关闭事件吗

HTML/CSS 打印布局问题 - 在 chrome 上添加额外页面

javascript - 从输入值中删除所有字母

html - SCSS/CSS 悬停在图像上

javascript - 鼠标光标随动限制为 body

android - 关于通用CSS媒体查询的反馈

javascript - 向下滚动并按住移动设备会显示位于视口(viewport)正下方的元素

javascript - 阻止事件在 DOM 中冒泡

html - 哇扎 : Video could not played when using dynamic smil