html - CSS - 2列布局

标签 html css multiple-columns

我想创建一个 2 列流式布局,左侧导航栏的高度应为 100%,标题的宽度应为 100%,内容部分的高度和宽度应为也为 100%,并且在 10 或 20 像素的所有边上应该有边距,在标题、导航和内容框之间也应该有边距。这是我的 fiddle :

https://jsfiddle.net/d2Lnq6sd/1/

header {
  position: relative;
  height: 75px;
  width: 100%;
  background-color: red;
  border: 1px solid black;
}

nav {
  position: relative;
  top: 20px;
  left: 0px;
  height: 100%;
  width: 200px;
  padding: 10px;
  background-color: blue;
  border: 1px solid black;
}

section {
  position: absolute;
  top: 110px;
  left: 240px;
  width: 100%;
  background-color: green;
  border: 1px solid black;
}

现在您可以看到导航栏的高度不是 100%,内容部分太宽。我的最终结果应该是这样的:

http://imageshack.com/a/img921/9425/UYp8Ah.png

尝试在谷歌上寻找关于这个问题的帮助,但我仍然不知道我应该使用什么,相对或绝对位置以及哪个用于哪个属性。有什么指点吗?

最佳答案

一切顺利:http://codepen.io/8odoros/pen/vKxVYv?editors=1100

  • 导航栏 100% 的高度
  • 内容部分也

html, body {
    height:calc(100% - 60px);
}
body {
  font-family: verdana;
  color: #fff;
}

.container {
  position: relative;
  margin: 10px;
  padding: 10px;
  height:100%;
  box-sizing:border-box;
}

header {
  float:left;
  height: 75px;
  width: 100%;
  background-color: red;
  border: 1px solid black;
  box-sizing:border-box;
}
nav {
  float:left;
  margin-top:20px;
  height: 100%;
  width: 200px;
  padding: 10px;
  background-color: blue;
  border: 1px solid black;
  box-sizing:border-box;
}

section {
  float:right;
  margin-top:20px;
  height:100%;
  padding: 10px;
  width:calc(100% - 220px); 
  background-color: green;
  border: 1px solid black;
  box-sizing:border-box;
}
<div class="container">

    <header>
        This is the header
    </header>
  
    <nav>
        This is the nav
    </nav>

    <section>
        This is the main section
    </section>
</div>

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

相关文章:

html - 如何使元素宽度为 : 100% minus padding?

javascript - 如何使用 Javascript 将 CSS 添加到新窗口?

javascript - 动态添加图像/ Canvas 上的 toDataURL

jquery - 弹出对话框背景100%高度

html - anchor 标签重复

html - "margin-top:auto"不工作

javascript - 使用 CSS 自动排列 2 列文本

java - 单for循环进入多列(JAVA)

python - 计算表格给定列中的所有字符串值并根据第三列对其进行分组

php mySQL 用 php 和 html 代码回显数据库内容