Css 左浮动的中间div?
我想把div放在中间,比如:Css 左浮动的中间div?,css,Css,我想把div放在中间,比如: <div style='width:100%;'> <div style='float:left; width=40px; height=40px;'></div> <div style='float:left; width=40px; height=40px;'></div> <div style='float:left; width=40px; height=40px;'
<div style='width:100%;'>
<div style='float:left; width=40px; height=40px;'></div>
<div style='float:left; width=40px; height=40px;'></div>
<div style='float:left; width=40px; height=40px;'></div>
...
</div>
| |
| X X X X X X |
| X X |
因此在上面,添加了足够多的子div,使第一行完全填满,然后两个附加的子div缠绕到另一行上,但它们自己也居中
什么样的风格适合这里
谢谢尝试将顶部div(宽度为100%;)设置为文本对齐:居中;然后给每个div一个显示:inline块;利润率:汽车
这将适用于chrome、opera、FF,但不适用于explorer
IE仅支持内联项的内联块,因此为了使其在IE中工作,请创建内部divs跨距
像这样
<div style="width:100%;text-align:center;">
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
<span style="margin:auto;background-color:red;width:100px;height:50px;display:inline-block;margin-bottom:5px;"> </span>
</div>
display:inline block
浮现在脑海中,但我不确定在这种情况下如何居中。对于初学者,应该使用双引号,而不是单引号来分隔HTML属性值。您的内联样式使用的是=
,而不是:
。。。