#background{position:absolute; wIDth:100%; height:100%; margin:0px; padding:0px; left:0px; right:0px;z-index:1;text-align: center;}#content{margin-left: auto;margin-right: auto; wIDth: 200px; z-index: 2; position: absolute;}
这是我的HTML:
<HTML><head><link REL="STYLESHEET" TYPE="text/CSS" href="style/myStyle.CSS"> </head><body > <div ID="background"><img src="images/backgroundimage.png" wIDth="100%" height="100%"> </div> <div ID="content"> <p>Here is some content</p> </div></body></HTML>
由于div必须定位为绝对,所以这样做:
margin: 0 auto;
不行.我不知道该怎么做.另外,我希望它垂直位于页面的中心.非常感谢帮助,谢谢.
编辑:我需要将背景放在一个单独的div中,以便它可以重新调整大小,并且内容不会显示位置是否相对.
解决方法<HTML><body> <div ID="background"> <div ID="content"> <p>Here is some content</p> </div> </div></body></HTML>
在不使用Jquery的情况下,将内容放在中间的更好的结构:
#background{background: url(images/backgroundimage.png) top no-repeat;wIDth:100%;height:100%;position:relative;}#content{position:absolute;top:50%;left:50%;wIDth :200px;height:200px;margin-left:-100px;margin-top:-100px;}总结
以上是内存溢出为你收集整理的将HTML元素置于页面中间全部内容,希望文章能够帮你解决将HTML元素置于页面中间所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)