admin管理员组文章数量:1277902
I am trying to create a control which contains multiple div's and all the div's are horizontally center align. as shown below.
I was able to able to float every div using float:left
css property. which give something like this
but ever div's are aligh left to their parent.
I have one ulternative solition to use javascript to position every div but I want to use css. Is it possible to achive this using css.
Thanks in advance
I am trying to create a control which contains multiple div's and all the div's are horizontally center align. as shown below.
I was able to able to float every div using float:left
css property. which give something like this
but ever div's are aligh left to their parent.
I have one ulternative solition to use javascript to position every div but I want to use css. Is it possible to achive this using css.
Thanks in advance
Share Improve this question edited Jan 6, 2015 at 15:42 lante 7,3464 gold badges38 silver badges58 bronze badges asked Jan 6, 2015 at 15:30 Faheem AlamFaheem Alam 5254 silver badges20 bronze badges 2- 2 switch from float, to display: inline-block, and text-align: center to the parent, and you should be good to go – RGLSV Commented Jan 6, 2015 at 15:33
- To avoid browser issues, make sure you don't leave any white space between divs when using inline-block. – Jason Williams Commented Jan 6, 2015 at 15:36
1 Answer
Reset to default 11This may do what you are trying to:
HTML:
<div class="parent">
<div class="child">Element 1</div>
<div class="child">Element 2</div>
</div>
CSS:
.child {
display: inline-block;
}
.parent {
text-align: center;
}
and the fiddle.
本文标签: javascripthow to horizontally center multiple div39s in a parent divStack Overflow
版权声明:本文标题:javascript - how to horizontally center multiple div's in a parent div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741271184a2369328.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论