twitter-bootstrap 是否可以水平居中对齐一排不加起来为 12 的引导跨度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15942858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:53:43  来源:igfitidea点击:

Is it possible to horizontally center align a row of bootstrap spans that don't add up to 12?

csstwitter-bootstrapalignmenthtml

提问by meiryo

<div class="row">
  <div class="span4"></div>
  <div class="span4"></div>
</div>

I understand that you need 12 spans in total. Is there a way to still center align the two spans I have horizontally? The above will just float to the left.

我知道您总共需要 12 个跨度。有没有办法仍然使我水平的两个跨度居中对齐?上面的只会浮动到左边。

I've tried putting a wrapper around them and margin auto'ng it but nothing happens.

我试过在它们周围放一个包装器并自动调整它,但没有任何反应。

I can go and remove the span class and just add a specified width but I need spanclass for fluid layout.

我可以去删除 span 类并只添加指定的宽度,但我需要span类进行流体布局。

采纳答案by Dmonix

If you want to center two columns of span4you can use offset param like this:

如果您想将两列居中,span4您可以使用这样的偏移参数:

<div class="row">
  <div class="span4 offset2"></div>
  <div class="span4"></div>
</div>

Remember this may crash in lower resolutions. To prevent that think about using fluid grid layout. This is done by changing

请记住,这可能会在较低的分辨率下崩溃。为了防止这种情况,请考虑使用流体网格布局。这是通过改变来完成的

<div class="row">

into

进入

<div class="row-fluid">

Hope that helps!

希望有帮助!