如何正确嵌套使用Bootstrap网格而不包装列?

huangapple go评论52阅读模式
英文:

How can I nest Bootstrap grid properly without wrapping columns?

问题

I want to make a grid of 8 cols left and 4 columns right. In the 4 columns on the right, I wish to further split it into 4 cols and 8 cols. It is important that the grid does not wrap.

This is my HTML:

<div class="container">
  <div class="row">
    <div class="col-sm-8 col-md-8">
      A
    </div>
    
    <div class="col-sm-4 col-md-4">
      <div class="col-sm-4 col-md-4">
        B
      </div>
      
      <div class="col-sm-8 col-md-8">
        C
      </div>
    </div>
  </div>
</div>

Unfortunately, C displays under B, which I do not want. How is it possible to stop the grid wrapping underneath, please?

英文:

I want to make a grid of 8 cols left and 4 columns right. In the 4 columns in the right, I wish to further split it up to 4 cols and 8 cols. It is important that the grid does not wrap.

This is my html:

&lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;col-sm-8 col-md-8&quot;&gt;
      A
    &lt;/div&gt;
    
    &lt;div class=&quot;col-sm-4 col-md-4&quot;&gt;
      &lt;div class=&quot;col-sm-4 col-md-4&quot;&gt;
        B
      &lt;/div&gt;
      
      &lt;div class=&quot;col-sm-8 col-md-8&quot;&gt;
        C
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

unfortunately, C displays under B which I do not want. How is it possible to stop the grid wrapping underneath, please?

答案1

得分: 3

你只需要为嵌套的列使用另一个row容器。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->
div {
  border: 1px solid black;
}

<!-- language: lang-html -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">

<div class="container">
    <div class="row">
       <div class="col-sm-8 col-md-8">
       A
       </div>
       <div class="col-sm-4 col-md-4">
         <div class="row">
           <div class="col-sm-4 col-md-4">
           B
           </div>
           <div class="col-sm-8 col-md-8">
           C
           </div>
         </div>
       </div>
    </div>
</div>

<!-- end snippet -->
英文:

You just need to use another row container for the nested column.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

div {
  border: 1px solid black;
}

<!-- language: lang-html -->

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;row&quot;&gt;
       &lt;div class=&quot;col-sm-8 col-md-8&quot;&gt;
       A
       &lt;/div&gt;
       &lt;div class=&quot;col-sm-4 col-md-4&quot;&gt;
         &lt;div class=&quot;row&quot;&gt;
           &lt;div class=&quot;col-sm-4 col-md-4&quot;&gt;
           B
           &lt;/div&gt;
           &lt;div class=&quot;col-sm-8 col-md-8&quot;&gt;
           C
           &lt;/div&gt;
         &lt;/div&gt;
       &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月26日 22:27:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定