日期:2014-05-17  浏览次数:20691 次

在不知道屏幕宽度情况下怎么怎么把div放到中间位置
我知道怎样设置到四边的距离
但不知道怎样设置居中

------解决方案--------------------
先这样:
body {
text-align:center;
}
然后页面最外层套一个div,假设id为wrap
#wrap {
margin:0 auto;
}
------解决方案--------------------
<style type= "text/css ">
<!--
#tq {
width: 100%;
text-align: center;
}
#tw {
width: 400px;
}
-->
</style>
<div id= "tq " align= "center "> <div id= "tw "> jhgfh </div> </div>
------解决方案--------------------
只改css,则firefox不兼容
------解决方案--------------------
不一定要改动,只要你最外层是个容器,不管是table还是div,加上那一句都可以的
------解决方案--------------------
#container {
background: #FFFFFF repeat-y center;
position: absolute;
left: 50%;
width: 760px;
margin-left: -380px;
padding: 0px;
margin-top: 5px;
height: 28px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #000000;}
我用的是这种,不管什么情况下,永远保持居中!