【问题标题】:bootstrap 4 column height issue after background color背景颜色后的bootstrap 4列高问题
【发布时间】:2020-08-14 20:34:52
【问题描述】:

我正在编写一个引导代码,在列内我已经定义了带有背景颜色的 div,但是,背景颜色只滚动到内容,并且由于数据变化,所以它看起来不均匀的数据,一些列更高,一些列更小。我选择这种方法是因为我需要列之间的间距,所以它应该看起来像带有圆边的卡片。我怎样才能有相同的柱高。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xl-2">
  <div class="rounded" style="background-color:aqua">
    <span>some text here</span>
  </div>
</div>
<div class="col-xl-2">
  <div class="rounded" style="background-color:pink">
    <span>some text here</span>
    <p>some more text</p>
    <p>some more text</p>
  </div>
</div>
<div class="col-xl-2">
  <div class="rounded" style="background-color:green">
    <span>some text here</span>
    <p>some more text here</p>
    <h5>extra work</h5>
  </div>
</div>
</div>
</div>

【问题讨论】:

    标签: html css bootstrap-4 responsive


    【解决方案1】:

    基本上这是duplicate

    列的高度相同,因为 Bootstrap 4 使用 flexbox。只需将h-100 (height:100%) 添加到圆形容器中即可填充列的高度。

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="container-fluid">
    <div class="row">
    <div class="col">
      <div class="rounded h-100" style="background-color:aqua">
        <span>some text here</span>
      </div>
    </div>
    <div class="col">
      <div class="rounded h-100" style="background-color:pink">
        <span>some text here</span>
        <p>some more text</p>
        <p>some more text</p>
      </div>
    </div>
    <div class="col">
      <div class="rounded  h-100" style="background-color:green">
        <span>some text here</span>
        <p>some more text here</p>
        <h5>extra work</h5>
      </div>
    </div>
    </div>
    </div>

    【讨论】:

    • 基本上我已经尝试给高度 100% 当我们切换到 ipad pro 测试模式时发生了什么,所有列都展开直到屏幕以空白列结束。
    • 那你为什么用xl?您不希望它们垂直堆叠吗?
    • 我在横向模式和纵向模式下都使用它。
    • 我不明白问题/问题是什么。您问如何获得已回答的全高列。您的问题中没有关于移动/ipad 等的任何内容...
    【解决方案2】:

    根据我对您的问题的理解,您希望所有 .col 的高度相同...

    height: 150px; 的CSS 属性(输入您想要的任何大小)添加到.col。但是,如果您希望背景成为 .col 的整个背景,则需要将其移动到 .col div 元素(我在其中放置蓝色和橙色)。

    附:蓝色和橙色只是为了告诉你每个.col的高度

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="container-fluid">
    <div class="row">
    <div class="col-xl-2" style="height: 150px; background-color: orange;">
      <div class="rounded" style="background-color:aqua">
        <span>some text here</span>
      </div>
    </div>
    <div class="col-xl-2" style="height: 150px; background-color: blue;">
      <div class="rounded" style="background-color:pink">
        <span>some text here</span>
        <p>some more text</p>
        <p>some more text</p>
      </div>
    </div>
    <div class="col-xl-2" style="height: 150px; background-color: orange;">
      <div class="rounded" style="background-color:green">
        <span>some text here</span>
        <p>some more text here</p>
        <h5>extra work</h5>
      </div>
    </div>
    </div>
    </div>

    【讨论】:

    • 任何基于技术或编码的方法,因为它是硬编码的方法。
    • 您可以为列 div 分配另一个类名,并一次将 CSS 添加到它们 (.foobar {height: 150px;})。如果我的解决方案和来自 @codeply-er 的另一个解决方案不是您想要的,那么我真的不确定我是否理解您想要的解决方案。
    • 哦,我已经在使用测量最高的柱子来实现高度 Funda,其他两个柱子保持相同。我只是想知道我是否错过了任何量身定制的引导类,它会产生魔力:)
    猜你喜欢
    • 1970-01-01
    • 2014-07-23
    • 2013-04-01
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 2018-06-30
    相关资源
    最近更新 更多