html - 具有两列的 Css 流体布局

标签 html css fluid-layout

<分区>

我需要这样布局:

----------------------
|   header           |
----------------------
|  N  |              |
|  A  |   CONTENT    |
|  V  |              |
|-----|              |
|     | ----BAR----  |
|EMPTY|              |
|     |              |
----------------------

我希望整体宽度为主体的 100%, 导航的宽度为 15%,但最小宽度为 120px。 栏(即内容 div 中的一个元素)的宽度必须是内容 div 的 100%。

在 html 中,我有一个限制,即导航 div 必须在内容 div 之前。

编辑: 我在 html 中的代码是

<div id="main">
<div id="header"></div>
<div id="nav"></div>
<div id="content><p id="bar">Title of paragraph</p></div>
</div>

我现在在 css 中的代码是:

#nav {
    float: left;
    width: 15%;
    min-width: 120px;
    }
#content{
    float: right;
}
#bar {
display: block;
background-color: #D2DEE4;
}

你能帮帮我吗?

最佳答案

我更喜欢 flexbox 方法,但是请记住这不适用于 IE9 及以下版本。

Flex-basis(又名 flex: {shrink} {grow} {flex-basis})是必需的,因为 flex 不能很好地处理 css 宽度。

*{
  margin: 0;
  padding: 0;
}

header{
  padding: 10px;
  width: 100%;
  background: #888;
}

.sidebar{
  padding: 10px;
  flex: 0 0 120px;
  background: #07f;
}

.content{
  padding: 10px;
  background: #ddd;
  width: 100%;
}

.container{
  display: flex;
  flex-direction: row;
}
<header>
  This is the header
</header>

<div class="container">
  <div class="sidebar">
     This is the sidebar
  </div>

  <div class="content">
    This is the content
    <br>
    test
  </div>
</div>

关于html - 具有两列的 Css 流体布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42139475/

上一篇:将 div 定位到光标位置的 Javascript 偏移量

下一篇:javascript - pointer-events none 在 IE 中的行为不符合预期

相关文章:

Python 3打印到文件并在字符串中混合 "and '

html - 使用@Page.Title 时不会出现注册标记!

javascript - 每页 localStorage?

css - Firefox 和 IE 中的悬停效果

php - 将 PHP while 循环代码的内容放入 DIV 中

css - 在所有屏幕尺寸上居中网站

javascript - 在 GAE 上的 Go 中显示由 html/template 产生的换行符

css - 居中 float 元素

html - 达到最小宽度时防止 css 中的列表溢出

html - 打破流体网格