2016-06-30 119 views
-1

我无法将div中的div元素对齐到居中。对齐Div中的Div元素

enter image description here

图像显示内部的div元素未在中心对齐。下面

<div class="row ph"> 
<div class="col-sm-3 phi"></div> 
<div class="col-sm-3 phi"></div> 
<div class="col-sm-3 phi"></div> 
</div> 

我的代码是给我的style.css如下。

.ph 
{ 
background-color: green; 
position : relative; 
margin : 0 auto; 
} 

.phi 
{ 
background-color: yellow; 
width: 20%; 
margin: 50px; 
height: 250px; 
} 

,当我搜索的解决方案,我发现对positionmargin auto属性。你能帮我解决这个问题吗?

+0

请为你想要做的事添加一些描述,你想对齐你的内部div在外部div的中间? – hassan

+0

是的。这是我的问题 –

回答

0

如此简单,只需添加

display: inline-block; 

得到水平内的div 并添加text-align: center;到外层div居中他们

你的CSS可能是这样的

.ph 
{ 
background-color: green; 
position : relative; 
width: 100%; 
text-align: center; 
} 

.phi 
{ 
background-color: yellow; 
width: 20%; 
margin: 30px; 
height: 250px; 
display: inline-block; 
} 

结帐: http://jsfiddle.net/xkqTR/2118/

+0

没有得到输出@Hassan仍然得到相同的输出在铬,即本地主机 –

+0

@anandmbs你想你在你的问题中提到的输出?你附加的图片?或者你想要集中你的内部divs?请查看jsfiddle链接 – hassan

+0

JS小提琴中的输出正常工作。但本地系统的输出不起作用 –