【问题标题】:Why do my columns behave differently after upgrading to Bootstrap 4?为什么升级到 Bootstrap 4 后我的列表现不同?
【发布时间】:2020-04-30 04:21:56
【问题描述】:

如果我在引导程序 3 中执行以下操作,那么一切都会按预期工作。但它在 bootstrap 4 中没有正确中断。请执行下面的示例,首先使用 BS4 运行,然后最后使用 BS3。

我希望它看起来像 Bootstrap 3.3.6

#orange_containers .row div {
  background: orange;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="orange_containers" class="">

  <div class="row no-gutters">
    <div class="col-sm-6">
      <div class="col-sm-3">
        <div class="icon">
          A
        </div>
      </div>
      <div class="col-sm-9">
        <div class="text">
          <h4>Test</h4>
          <p>
            I'm speaking with myself, number one, because I have a very good brain and I've said a lot of things. If Trump Ipsum weren’t my own words, perhaps I’d be dating it.
          </p>
        </div>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="col-sm-3">
        <div class="icon">
          B
        </div>
      </div>
      <div class="col-sm-9">
        <div class="text">
          <h4>Test</h4>
          <p>
            The other thing with Lorem Ipsum is that you have to take out its family. We have so many things that we have to do better... and certainly ipsum is one of them. We are going to make placeholder text great again. Greater than ever before.
          </p>
        </div>
      </div>
    </div>
  </div>

</div>

引导程序 4

#orange_containers .row div {
  background: orange;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div id="orange_containers" class="">

  <div class="row no-gutters">
    <div class="col-sm-6">
      <div class="col-sm-3">
        <div class="icon">
          A
        </div>
      </div>
      <div class="col-sm-9">
        <div class="text">
          <h4>Test</h4>
          <p>
            I'm speaking with myself, number one, because I have a very good brain and I've said a lot of things. If Trump Ipsum weren’t my own words, perhaps I’d be dating it.
          </p>
        </div>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="col-sm-3">
        <div class="icon">
          B
        </div>
      </div>
      <div class="col-sm-9">
        <div class="text">
          <h4>Test</h4>
          <p>
            The other thing with Lorem Ipsum is that you have to take out its family. We have so many things that we have to do better... and certainly ipsum is one of them. We are going to make placeholder text great again. Greater than ever before.
          </p>
        </div>
      </div>
    </div>
  </div>

</div>

注意:您必须全屏查看结果。

Try Bootstrap 3 example in Bootply

Try Bootstrap 4 Example in Bootply

【问题讨论】:

    标签: twitter-bootstrap twitter-bootstrap-3 bootstrap-4


    【解决方案1】:

    我认为您需要添加一个容器和一些行。此外,您不能将 col 作为另一个 col 的子级,它必须在一行内。详情见这里:https://getbootstrap.com/docs/4.4/layout/grid/#nesting

    尝试将您的代码更改为以下内容:

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
    
    <div id="orange_containers" class="">
    
        <div class="container-fluid">
    
            <div class="row no-gutters">
    
                <div class="col-sm-6">
                    <div class="row">
                        <div class="col-sm-3">
                            <div class="icon">
                                A
                            </div>
                        </div>
                        <div class="col-sm-9">
                            <div class="text">
                                <h4>Test</h4>
                                <p>
                                    I'm speaking with myself, number one, because I have a very good brain and I've said a lot of things. If Trump Ipsum weren’t my own words, perhaps I’d be dating it.
                                </p>
                                /div>
                            </div>
                        </div>
                    </div>
                </div>
    
                <div class="col-sm-6">
                    <div class="row">
                        <div class="col-sm-3">
                            <div class="icon">
                                B
                            </div>
                        </div>
                        <div class="col-sm-9">
                            <div class="text">
                                <h4>Test</h4>
                                <p>
                                    The other thing with Lorem Ipsum is that you have to take out its family. We have so many things that we have to do better... and certainly ipsum is one of them. We are going to make placeholder text great again. Greater than ever before.
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
    
            </div>
    
        </div>
    
    </div>
    

    【讨论】:

    • 它也可以在没有容器的情况下工作。我只需要添加一行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 2011-12-06
    • 1970-01-01
    • 2018-07-02
    相关资源
    最近更新 更多