简体   繁体   English

在Bootstrap 4中使3列的宽度和中心对齐75%

[英]Make 3 columns 75% width and center aligned in Bootstrap 4

I have the following bootply snippet: https://www.bootply.com/FHwoiollCJ 我有以下bootply片段: https ://www.bootply.com/FHwoiollCJ

As you can see, I have an element that is 75% of the width. 如您所见,我有一个元素是宽度的75%。

I'd like to center align the 3 items underneath this box so that the 1st and 3rd boxes don't overhang. 我想居中对齐此框下方的3个项目,以使第1个和第3个框不会悬空。 How do I do this? 我该怎么做呢?

<header class="masthead text-white">
  <div class="overlay"></div>
  <div class="container">
    <div class="row">
      <div class="col-lg-9 mx-auto" style="background:rgba(0,0,0,0.3);">
        <h1 class="mb-5">H1</h1>
        <p>We pride ourselves...</p>
      </div>
    </div>
    <div class="row">
      <div class="col-lg-3 mx-auto">
          <div class="" style="background:red">
            <h3>TEST</h3>
            <p>test</p>
        </div>
      </div>
      <div class="col-lg-3 mx-auto">
        <div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3" style="background:red">
          <h3>TEST</h3>
          <p>test</p>
        </div>
      </div>
      <div class="col-lg-3 mx-auto">
        <div class="features-icons-item mx-auto mb-0 mb-lg-3" style="background:red">
            <h3>TEST</h3>
            <p>test</p>
          </div>
        </div>
      </div>
      </div>
    </header>

You could use a nested grid solution: https://getbootstrap.com/docs/4.0/layout/grid/#nesting 您可以使用嵌套的网格解决方案: https : //getbootstrap.com/docs/4.0/layout/grid/#nesting

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <header class="masthead text-white"> <div class="overlay"></div> <div class="container"> <div class="row"> <div class="col-lg-9 mx-auto" > <div class="p-3" style="background:rgba(0,0,0,0.3);"> <h1 class="mb-5">H1</h1> <p>We pride ourselves...</p> </div> </div> </div> <div class="row"> <div class="col-lg-9 mx-auto"> <div class="row"> <div class="col-lg-4"> <div class="" style="background:red"> <h3>TEST</h3> <p>test</p> </div> </div> <div class="col-lg-4"> <div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3" style="background:red"> <h3>TEST</h3> <p>test</p> </div> </div> <div class="col-lg-4"> <div class="features-icons-item mx-auto mb-0 mb-lg-3" style="background:red"> <h3>TEST</h3> <p>test</p> </div> </div> </div> </div> </div> </div> </header> 

Here's a link to a bootply snippet . 这是bootply片段的链接。

I think your issue is with the padding added by bootstrap layout classes. 我认为您的问题与引导布局类添加的填充有关。 I've just juggled a few of your divs so that they are nested in an equal number of bootstrap classes (ie .col-lg-9 ). 我刚刚弄混了一些div,以便它们嵌套在相同数量的引导程序类中(即.col-lg-9 )。 This has lined things up nicely. 这很好地安排了一切。

I also had to add margin-bottom: 0px; 我还必须添加margin-bottom: 0px; to the paragraph in your wide red div so that the three grey divs below weren't pushed down. 到宽红色div中的段落,这样就不会压低以下三个灰色div。 Add introduced a new class padding-10 so that it looks similar to the original. Add引入了一个新的padding-10类,使其看起来与原始类相似。

Play around with the styling and I think this will do what you want, if not let me know. 试一下样式,我想这会做您想要的,如果没有让我知道的话。

<header class="masthead text-white">
  <div class="overlay"></div>
  <div class="container">
    <div class="row col-lg-9 mx-auto">
      <div class="col-lg-12 mx-auto">
        <div style="background:rgba(0,0,0,0.3);">
          <h1 class="mb-5">H1</h1>
          <p style="margin-bottom: 0px;">We pride ourselves...</p>
        </div>
      </div>
    </div>
    <div class="row col-lg-9 mx-auto">
      <div class="col-lg-4 mx-auto">
          <div class="" style="background:red">
            <h3>TEST</h3>
            <p>test</p>
        </div>
      </div>
      <div class="col-lg-4 mx-auto">
        <div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3" style="background:red">
          <h3>TEST</h3>
          <p>test</p>
        </div>
      </div>
      <div class="col-lg-4 mx-auto">
        <div class="features-icons-item mx-auto mb-0 mb-lg-3" style="background:red">
            <h3>TEST</h3>
            <p>test</p>
          </div>
        </div>
      </div>
      </div>
    </header>

try this: 尝试这个:

    <div class="overlay"></div>
<div class="container">
  <div class="row">
    <div class="col-lg-9 mx-auto" style="background:rgba(0,0,0,0.3);">
      <h1 class="mb-5">H1</h1>
      <p>We pride ourselves...</p>
    </div>
  </div>
  <div class="row">
    <div class="col-lg-9 mx-auto" style="padding-left: 0;padding-right: 0;">
    <div class="row">
      <div class="col-lg-4 mx-auto">
        <div class="" style="background:red">
          <h3>TEST</h3>
          <p>test</p>
        </div>
      </div>
      <div class="col-lg-4 mx-auto">
        <div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3" style="background:red">
          <h3>TEST</h3>
          <p>test</p>
        </div>
      </div>
      <div class="col-lg-4 mx-auto">
        <div class="features-icons-item mx-auto mb-0 mb-lg-3" style="background:red">
          <h3>TEST</h3>
          <p>test</p>
        </div>
      </div>
    </div>
  </div>
  </div>
</div>

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

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