【问题标题】:Unable to fully center 3 columns inside a fluid container in Bootstrap无法在 Bootstrap 的流体容器内完全居中 3 列
【发布时间】:2016-05-23 00:42:17
【问题描述】:

我试图在 流体容器 中以 偏移 1 将 3 列居中,但出于某种原因,所有 3列的左对齐比右对齐。

此外,当我调整窗口大小时,所有 3 列都会一直向左移动,而不是保持居中。

https://jsfiddle.net/DTcHh/16895/

我的问题是:

什么是使所有内容居中的最佳方式:图像、标题、文本和 Bootstrap 中的列? 注意:无论屏幕宽度如何,我都希望所有项目居中。

HTML:

<div class="container-fluid conle">

        <row>


        <div class="col-md-3 col-md-offset-1 col-sm-8 col-sm-offset-1 workscol">

        <img src="http://jsfiddle.net/img/logo.png" height =100px; alt="">
        <h2>Everything</h2>

        <p class="text-muted textworks">Sign up and shut up or i will pick a 10 pound dumbell
        and makes you got fetch it. Thank you for your patience. Have a treat</p>     

        </div>



       <div class="col-md-3 col-md-offset-1 col-sm-8 col-sm-offset-1 workscol">

           <img src="http://jsfiddle.net/img/logo.png" height =100px; alt="">
        <h2>Control Nothing</h2>
        <p class="text-muted textworks">Sign up and shut up or i will pick a 10 pound dumbell
        and makes you got fetch it. Thank you for your patience. Have a treat</p>    


        </div>


         <div class="col-md-3 col-sm-8 col-sm-offset-1 workscol">

          <img src="http://jsfiddle.net/img/logo.png" height =100px; alt="">
        <h2>Go Away</h2>
        <p class="text-muted textworks">Sign up and shut up or i will pick a 10 pound dumbell
        and makes you got fetch it. Thank you for your patience. Have a treat</p>    

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

CSS:

.workscol {max-width:345px;  }

.textworks {font-size:20px; }

请记住,我对引导程序还很陌生,但是按照教程,上面的代码是我能做的最好的。所以请务必解释我做错了什么。谢谢!

【问题讨论】:

    标签: twitter-bootstrap css twitter-bootstrap-3 containers col


    【解决方案1】:

    这是你想要的吗?

    http://codepen.io/anon/pen/pgqMWK

    HTML:

    <div class="container-fl
    
        uid conle">
          <row>
    
          <div class="col-md-3 col-md-offset-1 col-sm-8 col-sm-offset-1">
            <img src="http://jsfiddle.net/img/logo.png" height =100px; alt="">
            <h2>Everything</h2>
            <p class="text-muted textworks">Sign up and shut up or i will pick a 10 pound dumbell and make you go fetch it. Thank you for your patience. Have a treat,</p>     
          </div>
    
          <div class="col-md-3 col-md-offset-1 col-sm-8">
            <img src="http://jsfiddle.net/img/logo.png" height =100px; alt="">
            <h2>Everything</h2>
            <p class="text-muted textworks">Sign up and shut up or i will pick a 10 pound dumbell and make you go fetch it. Thank you for your patience. Have a treat,</p>     
          </div>
    
          <div class="col-md-3 col-md-offset-1 col-sm-8">
            <img src="http://jsfiddle.net/img/logo.png" height =100px; alt="">
            <h2>Everything</h2>
            <p class="text-muted textworks">Sign up and shut up or i will pick a 10 pound dumbell and make you go fetch it. Thank you for your patience. Have a treat,</p>     
          </div>
         </row>
        </div>
    

    CSS:

    .textworks {font-size:20px; }
    .conle {text-align:center; }
    

    是否有需要指定最大宽度的原因?

    【讨论】:

    • 这是部分答案,但列在您的代码中并未完全居中。列的位置更靠左,而不是完全居中。
    • “我正在尝试将 3 列居中,每个列在流体容器中的偏移量为 1”——这就是为什么它们没有完全居中。如果您希望它们完全居中每个容器,那么您需要删除偏移量,即col-md-offset-1col-sm-offset-1。或者,如果您希望将三个部分集中在整个页面中,同时仍保持每个部分内的偏移量,则需要创建一个容器。
    • 另外,如果您要完全删除偏移量,您可能希望将类分别更改为 col-md-4col-sm-4(因为有 3 个部分,并且引导程序使用 12 列网格规则)。
    • 最大宽度实际上是用来保持文本段落的简短。那我该如何居中呢? codepen.io/anon/pen/RrEXyG
    • 太好了,这正是我想要的。谢谢!
    猜你喜欢
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 2014-12-25
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多