【发布时间】:2014-08-27 02:00:08
【问题描述】:
我尝试将图像垂直居中放在身体中间,但似乎没有任何效果。我尝试过在这里找到的不同技巧(高度 100%、表格单元格、位置:相对...),但直到现在都没有运气。我的代码是 html:
<div id="container">
<div id="header">Header</div>
<div id="body">
<div class="image"></div>
</div>
<div id="footer">Footer</div>
</div>
CSS:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ccc;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center;
height: 200px;
width: 100%;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
我在这里做了一个小提琴:http://jsfiddle.net/dragoeco/hjcz6j0r/1/ 我正在寻找一个使用 IE8+ 的工作解决方案,所以也许有一种 jQuery 方法来完成这项工作?对我来说重要的是将页脚保持在视口底部,这就是为什么我为页脚使用绝对位置的原因。谢谢。
【问题讨论】:
标签: html css background-image vertical-alignment