HTML& CSS + Twitter Bootstrap:全页面布局或高度100% - Npx [英] HTML&CSS + Twitter Bootstrap: full page layout or height 100% - Npx
问题描述
我尝试进行以下布局:
+-------------------------------------------------+
| Header + search (Twitter navbar) |
+------------+------------------------------------+
| | |
| | |
|Navigation | Content column |
| | |
| | |
| | |
| | |
| | |
| | |
+------------+------------------------------------+
| Footer |
+-------------------------------------------------+
必须采取所有可用的高度&宽度,导航和内容列占用所有可用空间,并且在溢出时滚动,页脚应紧贴底部。
Layout must take all available height & width, navigation and content columns take all available space and scroll on overflow, footer should stick to bottom.
HTML现在看起来像这样:
HTML looks like this now:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link href="css/app.css" rel="stylesheet" media="screen">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="navbar">
<!-- navbar content -->
</div>
<div class="row-fluid columns">
<div class="span2 article-tree">
<!-- navigation column -->
</div>
<div class="span10 content-area">
<!-- content column -->
</div>
</div>
<div class="footer">
<!-- footer content -->
</div>
</div>
</body>
</html>
CSS:
body, html, .container-fluid { /// take all available height
height: 100%;
}
.article-tree {
color: #DCE6E5;
background: #2F323B;
}
.content-area {
overflow: auto;
height: 100%; /// explicit height to make scrolling work
}
.columns {
height: 100%; /// columns should take all height
margin-top: 42px; /// minus header
margin-bottom: 20px; // minus footer
}
.columns > div {
height: 100%; // make each column to take all available height
}
.footer {
background: red;
height: 20px;
}
理论上它应该工作,但columns.margin不工作期望。我认为应该使高度= 100% - magin,但它只是移动容器。
In theory it should work, but columns.margin doesn't work as I expect. I thought it should make height = 100% - magin, but it just moves the container.
我已经google和看到很多问题StackOverflow。所有这些都包括JavaScript或位置:绝对和手动定位。 IMHO他们比解决方案更黑客,我认为应该有一些更简单,更优雅和跨浏览器的方式来解决这个问题。
I've googled and seen numerous questions on StackOverflow. All of them include JavaScript or position: absolute and manual positioning. IMHO they're more hacks than a solutions, I think there should be some simpler and more elegant and cross-browser way to solve this problem.
那么如何使布局上述?也许Bootstrap可以帮助我(我看过文档,但没有提到像这样的情况)
So how do I make layout described above? Maybe Bootstrap can help me (I've looked through documentation, but there are no mentions of cases like this)?
推荐答案
在Stackoverflow上发现了一个职位,并实现了您的设计:
I've found a post here on Stackoverflow and implemented your design:
http:/ /jsfiddle.net/bKsad/25/
这是原始讯息: http://stackoverflow.com/a/5768262/1368423
这是您要查找的内容吗?
Is that what you're looking for?
HTML:
<div class="container-fluid wrapper">
<div class="row-fluid columns content">
<div class="span2 article-tree">
navigation column
</div>
<div class="span10 content-area">
content column
</div>
</div>
<div class="footer">
footer content
</div>
</div>
CSS:
html, body {
height: 100%;
}
.container-fluid {
margin: 0 auto;
height: 100%;
padding: 20px 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.columns {
background-color: #C9E6FF;
height: 100%;
}
.content-area, .article-tree{
background: #bada55;
overflow:auto;
height: 100%;
}
.footer {
background: red;
height: 20px;
}
这篇关于HTML& CSS + Twitter Bootstrap:全页面布局或高度100% - Npx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!