vin*_*a87 7 html css css3 responsive-design twitter-bootstrap-3
我为个人网站创建了一个新的布局.
我正在使用Twitter Bootstrap 3,我的初始布局是使用"Bootstrap with sticky footer"示例(http://getbootstrap.com/examples/sticky-footer-navbar/)
这是我的HTML:
<body>
<!-- Wrap all page content here -->
<div id="wrap">
<!-- Begin page navigation -->
<nav id="nav-container" class="navbar navbar-default container" role="navigation">
<div class="container">
<!-- Here I put a very normal Bootstrap 3 navbar -->
</div>
</nav>
<!-- Begin page content -->
<div id="main-container" class="container">
<!-- All my content goes here! -->
</div>
</div>
<!-- Begin page footer -->
<footer id="footer" class="container">
<div class="container">
</div>
</footer>
</body>
Run Code Online (Sandbox Code Playgroud)
Sticky Footer CSS:
html, body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto;
/* Negative indent footer by its height */
margin: 0 auto -100px;
/* Pad bottom by footer height */
padding: 0 0 100px;
}
/* Set the fixed height of the footer here */
#footer {
height: 100px;
}
Run Code Online (Sandbox Code Playgroud)
我的布局的自定义样式:
body {
/* Body's background will be grey */
background-color: #C0C0C0;
}
#main-container {
/* A box where I'll put the content will be white */
background-color: #FFFFFF;
}
#wrap {
height: 100%;
min-height: 100%;
}
#main-container {
min-height: 100%;
height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
此代码生成此布局:

但是,正如你所看到的那样,div #main-container直到布局结束时才会增长.在div保持与他的内容的高度.
我想要的是这个div总是填满整个页面,如下所示:

互联网上的许多解决方案都说我要修复min-height一些经过测试的价值,但这样我就无法保持网站的响应能力(这对我来说非常重要,因为我保持布局总是响应,这是我使用Bootstrap 3的主要原因).
其他解决方案用javascript计算div高度.我个人不喜欢这个解决方案.我知道我只能通过使用CSS来解决这个问题.
有人知道如何解决这个问题吗?
我认为min-height由于报告的错误,这不起作用。请参阅:stackoverflow.com/questions/8468066。
创造 #main-container 一直增长到最后的错觉的一个简单方法是将 #wrap 的背景颜色设置为与 #main-container 相同的值。
| 归档时间: |
|
| 查看次数: |
5354 次 |
| 最近记录: |