【发布时间】:2021-06-18 21:55:05
【问题描述】:
我正在尝试使用 align-items-stretch 来拉伸 div 的背景,并使用 align-items-center 来使内容居中(垂直!)。不知何故,当我使用很长的标题时,不会应用 align-items-center。
我做错了什么?
更新:添加了自己风格的 CSS + 来自源代码的特定引导程序 更新:当我应用 inline min-height 时,内容将垂直居中(这很好)。
<div class="col-6 grow d-flex align-items-stretch">
<div class="col-12 tile elevation-1">
<div class="row no-gutters align-items-center">
<div class="col-12 col-md-4">
<div class="col-12">
<img src="https://via.placeholder.com/512" alt="" class="img-fluid tile-image">
</div>
</div>
<div class="col-12 col-md-8 tile-product-content-horizontal" style="min-height:300px;">
<div class="col-12 ">
<span class="brand"> Brand name </span>
<h3> Short title </h3>
</div>
</div>
</div>
</div>
</div>
<div class="col-6 grow d-flex align-items-stretch">
<div class="col-12 tile elevation-1">
<div class="row no-gutters align-items-center">
<div class="col-12 col-md-4">
<div class="col-12">
<img src="https://via.placeholder.com/512" alt="" class="img-fluid tile-image">
</div>
</div>
<div class="col-12 col-md-8 tile-product-content-horizontal" style="min-height:300px;">
<div class="col-12 ">
<span class="brand"> Brand name </span>
<h3> This is a very long title which stretches the div </h3>
</div>
</div>
</div>
</div>
</div>
CSS:
.tile-product-content-horizontal {
padding: 20px 40px 20px 5px;
}
.tile {
border-radius: 16px;
background-color: #FFF;
margin-bottom: 20px;
background-image: url(assets/card-chevron.png);
background-repeat: no-repeat;
background-position: right 30px center;
}
/* BOOTSTRAP SPECIFIC */
.align-items-stretch {
align-items:stretch !important
}
.align-items-center {
align-items:center !important
}
.d-flex {
display:flex !important
}
【问题讨论】:
-
也添加css部分
-
添加了自己风格的 CSS + bootstrap
-
元素应该是什么样子的?
-
已应用。我刚刚测试过。为您的代码创建一个code snippet 并包含一张图片。
-
好的,我有一些工作:当我应用内联样式时:“min-height:300px;”元素垂直居中(这很好)。我可以在不应用最小高度的情况下执行此操作吗?
标签: css bootstrap-5