I am trying to create a control which contains multiple div's and all the div's are horizontally center align. as shown below.
我正在尝试创建一个包含多个div的控件,所有div都是水平居中对齐的。如下所示。
I was able to able to float every div using float:left
css property. which give something like this
我能够使用float:left css属性浮动每个div。像这样的东西?
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. Is it possible to achive this using css.
我有一个超本机实体来使用javascript来定位每个div但是我想使用css。是否有可能使用css实现这一点。
Thanks in advance
谢谢提前
1 个解决方案
#1
11
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.
和小提琴。
#1
11
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.
和小提琴。