Bootstrap 5带有h-100的div溢出父行

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

Bootstrap 5 div with h-100 overflows parent row

问题

在屏幕宽度大于等于 md 的情况下,具有类名 stackOverflowCom<div> 元素在使用 h-100 类时会超出父级 <div class="row"> 元素。你之所以需要使用 h-100 类,是因为你想将除了 "Red Keep" 和 "King's Landing" 之外的所有内容都对齐到卡片的底部。你可以如何实现这一目标?

任何帮助都会非常感激!

英文:

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

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

html {
  font-size: 14px;
}

.body {
  background-color: whitesmoke;
}

.long-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM&quot; crossorigin=&quot;anonymous&quot;&gt;

&lt;div class=&quot;container my-5&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;container-fluid rounded shadow bg-white border mb-4&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-4 p-0 me-2&quot;&gt;
          &lt;div id=&quot;carouselComponent&quot; class=&quot;carousel slide h-100&quot;&gt;
            &lt;div class=&quot;carousel-inner rounded h-100&quot;&gt;
              &lt;div class=&quot;carousel-item h-100 active&quot;&gt;
                &lt;img src=&quot;https://i.pinimg.com/originals/c8/a5/a8/c8a5a813afea19847217c765232b727d.jpg&quot; class=&quot;d-block w-100 h-100 object-fit-cover&quot; alt=&quot;...&quot;&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;button class=&quot;carousel-control-prev&quot; type=&quot;button&quot; data-bs-target=&quot;#carouselComponent&quot; data-bs-slide=&quot;prev&quot;&gt;
              &lt;span class=&quot;carousel-control-prev-icon&quot;&gt;&lt;/span&gt;
            &lt;/button&gt;
            &lt;button class=&quot;carousel-control-next&quot; type=&quot;button&quot; data-bs-target=&quot;#carouselComponent&quot; data-bs-slide=&quot;next&quot;&gt;
              &lt;span class=&quot;carousel-control-next-icon&quot;&gt;&lt;/span&gt;
            &lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;col p-3&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
            &lt;h5 class=&quot;mb-1&quot;&gt;&lt;a&gt;Red Keep&lt;/a&gt;&lt;/h5&gt;
            &lt;div class=&quot;text-truncate text-muted mb-1&quot;&gt;
              &lt;i class=&quot;fa fa-location-dot&quot;&gt;&lt;/i&gt; King&#39;s Landing
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;stackOverflowCom d-block d-md-flex justify-content-between align-items-end h-100&quot;&gt;
            &lt;div&gt;
              &lt;div class=&quot;mb-2&quot;&gt;&lt;span class=&quot;badge bg-primary&quot;&gt;0.0&lt;/span&gt; &lt;a href=&quot;#!&quot; class=&quot;text-muted&quot;&gt;(0 reviews)&lt;/a&gt;&lt;/div&gt;
              &lt;div class=&quot;long-text text-center&quot;&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc lobortis metus quam, sodales eleifend mauris scelerisque non. Integer tincidunt turpis quis varius malesuada. Morbi efficitur pretium mauris vitae tempor. Praesent ultricies arcu eget sagittis malesuada. Vivamus viverra varius scelerisque. &lt;br&gt;
                Suspendisse eget suscipit nulla, at feugiat felis. Curabitur eleifend lectus metus, sit amet convallis neque rhoncus efficitur. Phasellus ullamcorper interdum porta. Suspendisse potenti. Mauris sagittis felis tempus mauris venenatis pellentesque eget non augue. Aenean eu nisi faucibus, varius libero eget, vestibulum sem. Aliquam lacus est, vulputate ut ornare quis, blandit vel nisi. Cras rhoncus ante ipsum, sed sagittis risus aliquet eget.&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;mt-2&quot;&gt;
              &lt;div class=&quot;row justify-content-end align-items-baseline d-md-block&quot;&gt;
                &lt;div class=&quot;col-4 col-md-12 d-flex justify-content-center align-items-baseline&quot;&gt;
                  &lt;h3&gt;10000$&lt;/h3&gt;
                  &lt;span&gt;/day&lt;/span&gt;
                &lt;/div&gt;
                &lt;div class=&quot;col-4 col-md-12 d-flex justify-content-end&quot;&gt;
                  &lt;h6 class=&quot;text-decoration-line-through text-muted me-2&quot;&gt;19999&lt;/h6&gt;
                  &lt;h6 class=&quot;text-success&quot;&gt;-10%&lt;/h6&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;d-grid&quot;&gt;
                &lt;button class=&quot;btn btn-primary&quot;&gt;Book&lt;/button&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

codepen: https://codepen.io/peppapig19/pen/KKGjBoK

on md+ screens the div with class stackOverflowCom overflows parent row when uses h-100. the reason why i need h-100 in the first place, is i want to align everything except "Red Keep" and "King's Landing" to the bottom of the card. how can i achieve this?

any help is much appreciated!

答案1

得分: 0

d-md-flexflex-md-columnjustify-content-between类添加到父容器中。

<div class="col d-md-flex flex-md-column justify-content-between p-3">

stackOverflowCom容器中移除h-100justify-content-between,因为它们不需要(您可能还想删除align-items-end)。

<div class="stackOverflowCom d-block d-md-flex align-items-end">

在此代码片段中,只有上述两个部分需要翻译。

英文:

Add d-md-flex, flex-md-column, and justify-content-between classes to the parent container.<br>
&lt;div class=&quot;col d-md-flex flex-md-column justify-content-between p-3&quot;&gt;

Remove h-100 and justify-content-between from the stackOverflowCom container as they are not needed (you may also want to remove align-items-end)

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

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

html {
  font-size: 14px;
}

.body {
  background-color: whitesmoke;
}

.long-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM&quot; crossorigin=&quot;anonymous&quot;&gt;

&lt;div class=&quot;container my-5&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;container-fluid rounded shadow bg-white border mb-4&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-4 p-0 me-2&quot;&gt;
          &lt;div id=&quot;carouselComponent&quot; class=&quot;carousel slide h-100&quot;&gt;
            &lt;div class=&quot;carousel-inner rounded h-100&quot;&gt;
              &lt;div class=&quot;carousel-item h-100 active&quot;&gt;
                &lt;img src=&quot;https://i.pinimg.com/originals/c8/a5/a8/c8a5a813afea19847217c765232b727d.jpg&quot; class=&quot;d-block w-100 h-100 object-fit-cover&quot; alt=&quot;...&quot;&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;button class=&quot;carousel-control-prev&quot; type=&quot;button&quot; data-bs-target=&quot;#carouselComponent&quot; data-bs-slide=&quot;prev&quot;&gt;
              &lt;span class=&quot;carousel-control-prev-icon&quot;&gt;&lt;/span&gt;
            &lt;/button&gt;
            &lt;button class=&quot;carousel-control-next&quot; type=&quot;button&quot; data-bs-target=&quot;#carouselComponent&quot; data-bs-slide=&quot;next&quot;&gt;
              &lt;span class=&quot;carousel-control-next-icon&quot;&gt;&lt;/span&gt;
            &lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;col d-md-flex flex-md-column justify-content-between p-3&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
            &lt;h5 class=&quot;mb-1&quot;&gt;&lt;a&gt;Red Keep&lt;/a&gt;&lt;/h5&gt;
            &lt;div class=&quot;text-truncate text-muted mb-1&quot;&gt;
              &lt;i class=&quot;fa fa-location-dot&quot;&gt;&lt;/i&gt; King&#39;s Landing
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;stackOverflowCom d-block d-md-flex align-items-end&quot;&gt;
            &lt;div&gt;
              &lt;div class=&quot;mb-2&quot;&gt;&lt;span class=&quot;badge bg-primary&quot;&gt;0.0&lt;/span&gt; &lt;a href=&quot;#!&quot; class=&quot;text-muted&quot;&gt;(0 reviews)&lt;/a&gt;&lt;/div&gt;
              &lt;div class=&quot;long-text text-center&quot;&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc lobortis metus quam, sodales eleifend mauris scelerisque non. Integer tincidunt turpis quis varius malesuada. Morbi efficitur pretium mauris vitae tempor. Praesent ultricies arcu eget sagittis malesuada. Vivamus viverra varius scelerisque. &lt;br&gt;
                Suspendisse eget suscipit nulla, at feugiat felis. Curabitur eleifend lectus metus, sit amet convallis neque rhoncus efficitur. Phasellus ullamcorper interdum porta. Suspendisse potenti. Mauris sagittis felis tempus mauris venenatis pellentesque eget non augue. Aenean eu nisi faucibus, varius libero eget, vestibulum sem. Aliquam lacus est, vulputate ut ornare quis, blandit vel nisi. Cras rhoncus ante ipsum, sed sagittis risus aliquet eget.&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;mt-2&quot;&gt;
              &lt;div class=&quot;row justify-content-end align-items-baseline d-md-block&quot;&gt;
                &lt;div class=&quot;col-4 col-md-12 d-flex justify-content-center align-items-baseline&quot;&gt;
                  &lt;h3&gt;10000$&lt;/h3&gt;
                  &lt;span&gt;/day&lt;/span&gt;
                &lt;/div&gt;
                &lt;div class=&quot;col-4 col-md-12 d-flex justify-content-end&quot;&gt;
                  &lt;h6 class=&quot;text-decoration-line-through text-muted me-2&quot;&gt;19999&lt;/h6&gt;
                  &lt;h6 class=&quot;text-success&quot;&gt;-10%&lt;/h6&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;d-grid&quot;&gt;
                &lt;button class=&quot;btn btn-primary&quot;&gt;Book&lt;/button&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月1日 14:42:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379289.html
匿名

发表评论

匿名网友

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

确定