简体   繁体   English

Bootstrap网格不是居中对齐的问题

[英]Bootstrap grid is not center aligned issue

I am using bootstrap library. 我正在使用引导程序库。 So, I was trying to make three grids in while building a website. 因此,我在构建网站时尝试制作三个网格。 It's responsive but, not enough. 它具有响应能力,但还不够。 And I cannot center align the grids. 而且我无法居中对齐网格。 But, manually it can be done with a customized class or an ID. 但是,可以通过自定义类或ID手动完成。 For an example let's say i'd like to get the view for tablet view... grids are coming like this... This is how it shows. 举个例子,假设我要获取平板电脑视图的视图...网格就这样显示了 ... 这就是它的显示方式。 The grid shows five years is not centered enough. 网格显示五年还不够集中。 it's giving an odd look. 它看起来很奇怪。

What's the way to get to move the '5years' grid to center when the tablet view is viewed. 查看平板电脑视图时,如何将“ 5年”网格移到中心。

I am attaching my code here. 我在这里附上我的代码。

       <!-- Here are all THREE COLUMNS which says about YEARS GRID  -->
<!-- 1st -->
<div class="row text-center center" id="alignment-margin">

  <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 col-tn-12 container " id="section-customization" id="alignment-margin">
    <h3 id="pricing-font">
      3 years
      <br/>
      <hr id="small-line">
    </h3>
    <p>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
    </p>
    <button class="btn btn-success rounded customize-button" id="tryButton" type="button">
      Try it now for free
    </button>
  </div>
  <!-- SECOND -->
  <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 col-tn-12 container " id="section-customization" id="alignment-margin">
    <h3 id="pricing-font">
      1 year
      <br/>
      <hr id="small-line">
    </h3>
    <p>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
    </p>
    <button class="btn btn-success rounded" id="tryButton" type="button">
      Try it now for free
    </button>
  </div>
  <!-- THIRD -->
  <div class="col-lg-4 col-md-4 col-sm-4  col-xs-12 col-tn-12 container" id="section-customization" id="alignment-margin">
    <h3 id="pricing-font">
      5 years
      <br/>
      <hr id="small-line">
    </h3>
    <p>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
      <i class="fa fa-check" id="icon_color">
        &nbsp
      </i>
      interdum et malesuada
      <br/><br/>
    </p>
    <button class="btn btn-success rounded customize-button" id="tryButton" type="button">
      Try it now for free
    </button>
  </div>
</div>

You can use a offset for that. 您可以为此使用偏移量。 This is some extra space, before the column is shown. 在显示该列之前,这是一些额外的空间。 In your example you want to center a column with the class col-md-4. 在您的示例中,您想使列以类col-md-4居中。

In total there are 12 columns, so to center your 5-years block, we need a 4 column offset. 总共有12列,因此要使您的5年区块居中,我们需要4列偏移量。

Add the following classes to the last block for only applying to small devices: 将以下类添加到最后一个块中,以仅适用于小型设备:

col-sm-offset-3 col-md-offset-0

The columns at the top are not centered now. 顶部的列现在未居中。 You can use a offset there too, or you can adjust the width. 您也可以在其中使用偏移量,也可以调整宽度。 With the example of your code below, I have adjusted the width. 在下面的代码示例中,我调整了宽度。 More info about the offset classed can be found here 有关偏移量分类的更多信息,请参见此处

Here is what you want: 这是您想要的:

<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 col-tn-12 container " id="section-customization" id="alignment-margin">
    <h3 id="pricing-font">
        3 years
        <br/>
        <hr id="small-line">
    </h3>
    <p>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
    </p>
    <button class="btn btn-success rounded customize-button" id="tryButton" type="button">
        Try it now for free
    </button>
</div>
<!-- SECOND -->
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 col-tn-12 container " id="section-customization" id="alignment-margin">
    <h3 id="pricing-font">
        1 year
        <br/>
        <hr id="small-line">
    </h3>
    <p>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
    </p>
    <button class="btn btn-success rounded" id="tryButton" type="button">
        Try it now for free
    </button>
</div>
<!-- THIRD -->
<div class="col-lg-4 col-md-4 col-sm-6 col-sm-offset-3 col-md-offset-0  col-xs-12 col-tn-12 container" id="section-customization" id="alignment-margin">
    <h3 id="pricing-font">
        5 years
        <br/>
        <hr id="small-line">
    </h3>
    <p>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
        <i class="fa fa-check" id="icon_color">
            &nbsp
        </i>
        interdum et malesuada
        <br/><br/>
    </p>
    <button class="btn btn-success rounded customize-button" id="tryButton" type="button">
        Try it now for free
    </button>
</div>

Hope this is what you wanted to accomplish 希望这就是你想要完成的

 <div class="container"> <div class="row"> <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"> FIRST BLOCK </div> <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"> SECOND BLOCK </div> <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"> THIRD BLOCK </div> </div> </div> 

I found the solution for this. 我找到了解决方案。 But couldn't update. 但是无法更新。 As bootstrap has it's own class to display the grids, we have to customize the classes according to our requirements. 由于引导程序具有自己的类来显示网格,因此我们必须根据需求自定义类。 The issue with the question is, making it responsive. 问题的问题在于,使其具有响应能力。 Of course media queries should be used. 当然,应该使用媒体查询。 https://css-tricks.com/snippets/css/media-queries-for-standard-devices/ https://css-tricks.com/snippets/css/media-queries-for-standard-devices/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM