以主要居民为中心

时间:2010-11-05 14:31:10

标签: css

我有一个div,里面是其他div。我的div是:<div id="Table_01"></div>

我如何居中,以便所有其他div都居中?

5 个答案:

答案 0 :(得分:3)

margin-left: auto;
margin-right: auto;

并确保它没有100%width值。

- 编辑: 由于您使用的是具有已知宽度的position: absolute;(在这种情况下为900px),您可以这样做:

left: 50%;
margin-left: -450px;

其中-450px是宽度的一半,否定。

答案 1 :(得分:0)

inner_div { margin:0 auto; }

垂直居中:

inner_div { position:absolute; top:50%; margin-top:-300px; }

答案 2 :(得分:0)

这是我的css:

#Table_01 {
    position:absolute;
    left:0px;
    top:0px;
    width:900px;
    height:600px;
}

#index-01 {
    position:absolute;
    background-color:#003366;
    left:0px;
    top:0px;
    width:900px;
    height:30px;
}

#index-02 {
    position:absolute;
    left:0px;
    top:30px;
    width:900px;
    height:72px;
}

#index-03 {
    position:absolute;
    left:0px;
    top:102px;
    width:900px;
    height:27px;
}

#index-04 {
    position:absolute;
    left:0px;
    top:129px;
    width:223px;
    height:223px;
}

#index-05 {
    position:absolute;
    left:223px;
    top:129px;
    width:382px;
    height:174px;
}

#index-06 {
    position:absolute;
    left:605px;
    top:129px;
    width:295px;
    height:223px;
}

#index-07 {
    position:absolute;
    left:223px;
    top:303px;
    width:382px;
    height:49px;
}

#index-08 {
    position:absolute;
    left:0px;
    top:352px;
    width:475px;
    height:183px;
}

#index-09 {
    position:absolute;
    left:475px;
    top:352px;
    width:425px;
    height:183px;
}

#index-10 {
    position:absolute;
    left:0px;
    top:535px;
    width:900px;
    height:34px;
}

#index-11 {
    position:absolute;
    background-color:#003366;
    left:0px;
    top:569px;
    width:900px;
    height:31px;
}

我的HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="http://localhost/assets/css/td.css" />
<title>Training Day</title>

<body style="margin: 0px; background-color: rgb(255, 255, 255);">
<div id="Table_01">
<div id="index-01"> &nbsp; &nbsp;$today is<br>
</div>
<div id="index-02"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; $logo and
$searchbox<br>
</div>
<div id="index-03"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;Navigation<br>
</div>
<div id="index-04"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;Box 1<br>
</div>
<div id="index-05"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
Front page picture holder<br>
</div>
<div id="index-06"> &nbsp; &nbsp; &nbsp; Trending Topics<br>
</div>
<div id="index-07"> &nbsp; &nbsp; Heading author and location</div>
<div id="index-08"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tabs<br>
</div>
<div id="index-09"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; Twitter Live Feeds<br>
</div>
<div id="index-10"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; Stats bar<br>
</div>
<div id="index-11"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Footer<br>
</div>
</div>
<!-- End Save for Web Slices -->
</body>
</html>

答案 3 :(得分:0)

应该有效:

Table_01 {

position:absolute; 
margin-left:-300px;
left:50%;
width:900px; 
height:600px; 

}

答案 4 :(得分:0)

这对我来说总是有用的。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
    <style type="text/css">
        body {
          text-align: center;
        }

        #mainsite {
           width: 770px;
           margin: auto;
           text-align: left;
           background-color: red;
        }
    </style>
</head>
<body>

<div id="mainsite">
    whee
</div>

</body>
</html>