2013-03-12 80 views
-7
#container { 
width: 960px; 
margin-left: auto; 
margin-right: auto; 
height: auto; } 

#large_box { 
text-align: center; 
width: 960px; 
margin-left: auto; 
margin-right: auto; 
height: auto; } 

#searchbcid { 
position: absolute; 
left: 400px; 
margin-left: 50px; 
top: 280px; } 

#createbcid { 
position: absolute; 
margin-left: 250px; 
top: 280px; 
left: 550px; } 

#loginpos { 
position: absolute; 
margin-left: 20px; 
left: 30px; 
top: 280px; } 

在我的html中有一个名为container的div。所有其他div s被放置在容器内。 另一个div即large_box其中包含3个其他div的诸如loginpos,searchbcid,createbcid如何居中div

但我无法对齐divlarge_box

我该如何居中对齐它?

+2

请提供您的HTML代码。 – 2013-03-12 10:06:02

+0

提供了一个小提琴 – 2013-03-12 10:12:34

+0

可能重复的[如何在div中居中div - 水平?](http://stackoverflow.com/questions/114543/how-to-center-a-div-in-a-div-水平) – Kara 2013-10-17 20:42:57

回答

0

在你的CSS只使用 margin:0 auto; 有一些div的宽度然后它会自动对齐在提供的宽度的中心。

快乐编码...

0

CSS:

#wrapper_div{ 
width:500px; 
height:500px; 
} 

#inner_div{ 
width:200px; 
margin:0 auto; 
} 

HTML:

<div id="wrapper_div"> 
<div id="inner_div"> 
Centred content here! 
</div> 
</div 
0

这对我的作品。

CSS

div#center{ 
     width:250px; 
     margin:0 auto; 
     background-color:yellow; 
} 

/* To support IE */ 
div#parent{ 
     align:center; 
} 

HTML

<div id="parent">  
     <div id="center"> 
     I'm in the middle! 
     </div> 
    </div> 

JSFiddle Link

0

试试你的页边距设置为0的汽车,它将水平居中的容器内的元素与指定的宽度。

#large_box { 
text-align: center; 
width: 960px; 
margin: 0 auto; 
height: auto; } 
0

使用此CSS为div。它将水平居中。

#large_box { 
    width: 960px; 
    margin: 0 auto; 
}