我正在尝试添加一个 div block ,使其位于屏幕中央。我只有一张固定的背景图片,它在做一些奇怪的事情。
CSS:
body {
margin:0;
padding:0;
}
#middle { <--- the white div block
background-color:#FFF;
display:block;
width:750px;
height:750px;
margin:0 auto 0 auto;
margin-top:15px;
position:relative;
overflow:hidden;
}
#bigbg { <-- background image
height:auto;
width:100%;
z-index:-100;
min-height:100%;
min-width:100%;
margin-left:0%;
position:fixed;
margin-top:0px;
}
HTML:
<div id='middle'>
</div>
<img src="images/backgroundmain.jpg" id="bigbg">
看起来像这样:
我希望白色的 div block 居中。有没有更好的方法来应用背景图像?我能够通过将 background-image:url
属性添加到 html 来实现我想要的,但是我无法添加我想要的所有属性,例如固定边距/宽度等。
最佳答案
将 margin:0 auto 0 auto;
改为 margin:0px auto;
中间类
关于html - 将div定位在中心css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19614602/