[英]how to horizontally center multiple div's in a parent div
I am trying to create a control which contains multiple div's and all the div's are horizontally center align. 我正在尝试创建一个包含多个div的控件,并且所有div都是水平居中对齐的。 as shown below.
如下所示。
I was able to able to float every div using float:left
css property. 我能够使用
float:left
css属性浮动每个div。 which give something like this 给出这样的东西
but ever div's are aligh left to their parent. 但是div总是留给他们的父母。
I have one ulternative solition to use javascript to position every div but I want to use css. 我有一个替代解决方案使用javascript来定位每个div但我想使用CSS。 Is it possible to achive this using css.
是否有可能使用CSS实现这一目标。
Thanks in advance 提前致谢
This may do what you are trying to: 这可能会做你想要的:
HTML: HTML:
<div class="parent">
<div class="child">Element 1</div>
<div class="child">Element 2</div>
</div>
CSS: CSS:
.child {
display: inline-block;
}
.parent {
text-align: center;
}
and the fiddle . 和小提琴 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.