任何帮助将不胜感激!!
我正在处理的页面在这里 http://www.iknowpost.com/
我试图做的是将背景图像拉伸(stretch)到 100% 高度,而不管查看者的屏幕大小如何,同时始终使图像在页面上水平居中。到目前为止,我已经弄清楚了 100% 的高度,但我一直在尝试弄清楚如何将它水平居中,但没有成功——目前它是固定的 left: 0px;我认为这应该很简单。我的代码在下面,也许这不是解决这个问题的正确方法。谢谢!
<style type="text/css">
#background {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}
.stretch {
height:100%;
}
</style>
</head>
<body>
<div id="background">
<img src="logo.jpg" class="stretch" alt="" />
</div>
</body>
</html>
最佳答案
也许这会有所帮助
<html>
<head>
<style type="text/css">
#background {
width: 700px;
height: 100%;
margin: 0 auto;
z-index: -1;
}
.stretch{
height:100%;
}
</style>
</head>
<body>
<div id="background">
<img src="logo.jpg" class="stretch" alt="" />
</div>
</body>
关于CSS 图像背景 - 将高度拉伸(stretch)到 100% 但保持图像在页面上水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7153053/