如何将 Bootstrap div 与“spanX"类居中? [英] How do I center a Bootstrap div with a 'spanX' class?
问题描述
我使用引导程序并试图将 div(span7) 居中:
<div id="main" class="span7">Lorem ipsum dolor 坐 amet
我的 css 代码是:
#main{边距:0px 自动;}
但它没有设置在中心.我如何设置中心?
编辑
span7
在 Bootstrap 4 中现在是 col-7
并且不推荐使用 row-fluid(代替这个,使用 container-fluid
和 <代码>行代码>).
Twitter 的引导程序 .span
类浮动到左侧,因此它们不会按常规方式居中.因此,如果您想让 span
居中,只需将 float:none
添加到您的 #main
规则即可.
CSS
#main {保证金:0 自动;浮动:无;}
I use bootstrap and am trying to center a div(span7) like that:
<div class="row-fluid">
<div id="main" class="span7">
Lorem ipsum dolor sit amet
</div>
</div>
my css code is:
#main{
margin:0px auto;
}
But it isn't set at the center. How can i set center?
EDIT
span7
is now col-7
in Bootstrap 4 and row-fluid is deprecated(Instead of this, use container-fluid
and row
).
Twitter's bootstrap .span
classes are floated to the left so they won't center by usual means. So, if you want it to center your span
simply add float:none
to your #main
rule.
CSS
#main {
margin:0 auto;
float:none;
}
这篇关于如何将 Bootstrap div 与“spanX"类居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!