html - CSS一页纸布局

标签 html css

我正在为一页纸的基本布局而苦苦挣扎。

这是我的代码:

section {
  position: relative;
  height: 100vh;
}

.section-single>.arrow {
  position: absolute;
  left: 50%;
  bottom: 10%;
}

.section-double>.content-left {
  width: 50%;
  float: left;
  background: gray;
}

.section-double>.content-right {
  width: 50%;
  float: left;
  background: black;
}

#section1 {
  background: green;
}

#section2 {
  background: red;
}

#section3 {
  background: yellow;
}
<section class="section-single" id="section1">
  <iframe src="https://www.youtube.com/watch?..."></iframe>
  <a href="#section2"><span class="arrow">section 2</span></a>
</section>
<section class="section-double" id="section2">
  <div class="content-left" id="div1">
  </div>
  <div class="content-right" id="div2">
</section>
<section class="section-double" id="section3">
  <div class="content-left" id="div3">
  </div>
  <div class="content-right" id="div4">
</section>

它应该是这样的:
Baisc layout

正如您在 css 中看到的,每个部分都应该有可用的全屏大小,而 div 应该有页面的 50%。但是,div 定位未按预期工作(由 .section-double > .content-left.section-double > .content-right 中的背景属性检查.

你能帮帮我吗?

最佳答案

您可以将 flexbox 用于此布局:

body {
  margin:0;
}
.container {
  display:flex;          /* set the container to flex */
  flex-wrap:wrap;        /* allow children to wrap */
  flex-direction:row;    /* line up children in a row - default value not needed */
}
.container > div {
  min-height:100vh;        /* moved as per comments below */
  border:1px solid black;
  box-sizing:border-box;   /* demo borders only */
}
.full-width {
  width:100%;              
}
.half-width {
  width:50%;
}
<div class="container">
  <div class="full-width">
    section one
  </div>
  <div class="half-width">
    div 1
  </div>
  <div class="half-width">
    div 2
  </div>
  <div class="half-width">
    div 3
  </div>
  <div class="half-width">
    div 4
  </div>
</div>

关于html - CSS一页纸布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52149345/

相关文章:

html - 并排显示两个 div 元素的文本溢出

javascript - 如何在不更改 url 的情况下在带有参数的页面之间跳转

html - ul 子弹未对准

html - 如何在下拉选项中定位背景图片

javascript - 使用 "choose file"输入更改 div backgroundImage

font-family 的 CSS 变量是 "invalid property"即使变量外的相同字符串很好

html - 背景的不透明度,而不是字体

html - 谁能告诉我为什么我的 div 之间有 <body> 空间?

html - IOS8 : whole page scrolls down when input in fixed footer gets focus

javascript - 使用纯 css3 的键盘导航