gpt4 book ai didi

javascript - 将 div 对齐到 Bootstrap4 卡体的底部

转载 作者:太空宇宙 更新时间:2023-11-04 06:15:49 25 4
gpt4 key购买 nike

我正在使用引导卡。我有卡片页眉和卡片页脚,它们工作得很好。在卡片体中,我有一个卡片标题。此标题在卡体中可以占 1 或 2 行。同样在这个卡片体中,我在一个 div 中有一些信息。我想将此信息 div 与卡片主体底部对齐,因为我使用 row/col 来很好地对齐内容,但是因为 1 个卡片标题是 1 行,另一个是 2 行,当您查看页面中的卡片时,此附加信息不会我认为卡片和底部对齐可以解决这个问题。

所以基本上我希望橙色的 div 在卡片底部排成一行,因为这样在视觉上它们会在卡片上看起来排成一行。

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />

<style>
.box {
position: relative;
display: inline-block;
width: 340px;
height: 300px;
background-color: #fff;
border-radius: 5px;
}

.box:hover {
/*-webkit-transform: scale(1.10, 1.10);
transform: scale(1.10, 1.10);*/
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.3);
}
</style>

<div class="container" style="margin-top: 25px;">
<div class="row">
<div class="col">

<div class="box" style="margin-right: 30px; margin-bottom: 30px;">
<div class="card" style="width: 100%; height: 100%;">

<!-- CARD HEADER -->
<div class="card-header" style="margin: 0px;">
Header Stuff
</div>

<!-- CARD BODY -->
<div class="card-body" style="cursor: pointer;">
<div class="row">
<div class="col">
<h6 class="card-title">This is a 1 line title</h6>
</div>
</div>

<!--<div class="d-flex align-items-center">-->
<div class="container" style="background-color: orangered">
<div class="row">
<div class="col-4">
Starts On:
</div>
<div class="col">
1/1/2019
</div>
</div>
<div class="row">
<div class="col-4">
Ends On:
</div>
<div class="col">
12/31/2019
</div>
</div>
<div class="row">
<div class="col-4">
#:
</div>
<div class="col">
52
</div>
</div>
</div>
<!--</div>-->
</div>

<!-- CARD FOOTER -->
<div class="card-footer">
Footer stuff
</div>

</div>
</div>

<div class="box" style="margin-right: 30px; margin-bottom: 30px;">
<div class="card" style="width: 100%; height: 100%;">

<!-- CARD HEADER -->
<div class="card-header" style="margin: 0px;">
Header stuff
</div>

<!-- CARD BODY -->
<div class="card-body" style="cursor: pointer;">
<div class="row">
<div class="col">
<h6 class="card-title">This is a longer description that will span 2 rows making things not line up right between cards</h6>
</div>
</div>

<!--<div class="d-flex align-items-center">-->
<div class="container" style="background-color: orangered">
<div class="row">
<div class="col-4">
Starts On:
</div>
<div class="col">
1/1/2020
</div>
</div>
<div class="row">
<div class="col-4">
Ends On:
</div>
<div class="col">
12/31/2020
</div>
</div>
<div class="row">
<div class="col-4">
#:
</div>
<div class="col">
10
</div>
</div>
</div>
<!--</div>-->
</div>

<!-- CARD FOOTER -->
<div class="card-footer">
Footer stuff here
</div>

</div>
</div>

</div>
</div>
</div>

最佳答案

我做了几件事:

  • 添加了 position:absolute,与底部有一些 (24%) 间隙;
  • container 类实现了 100% 的宽度,这就是盒子现在超出边界的原因;
  • card-body 类实现了 20px 的填充
  • 为了获得准确的样式,我们从 100% 宽度(来自容器容器)中移除了 20px 的宽度

完整片段如下:

.box {
position: relative;
display: inline-block;
width: 340px;
height: 300px;
background-color: #fff;
border-radius: 5px;
}

.box:hover {
/*-webkit-transform: scale(1.10, 1.10);
transform: scale(1.10, 1.10);*/
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.3);
}

.orangeRedClass {
position: absolute;
bottom: 24%;
width: calc(100% - 40px) !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />


<div class="container" style="margin-top: 25px;">
<div class="row">
<div class="col">

<div class="box" style="margin-right: 30px; margin-bottom: 30px;">
<div class="card" style="width: 100%; height: 100%;">

<!-- CARD HEADER -->
<div class="card-header" style="margin: 0px;">
Header Stuff
</div>

<!-- CARD BODY -->
<div class="card-body" style="cursor: pointer;">
<div class="row">
<div class="col">
<h6 class="card-title">This is a 1 line title</h6>
</div>
</div>

<!--<div class="d-flex align-items-center">-->
<div class="container orangeRedClass" style="background-color: orangered">
<div class="row">
<div class="col-4">
Starts On:
</div>
<div class="col">
1/1/2019
</div>
</div>
<div class="row">
<div class="col-4">
Ends On:
</div>
<div class="col">
12/31/2019
</div>
</div>
<div class="row">
<div class="col-4">
#:
</div>
<div class="col">
52
</div>
</div>
</div>
<!--</div>-->
</div>

<!-- CARD FOOTER -->
<div class="card-footer">
Footer stuff
</div>

</div>
</div>

<div class="box" style="margin-right: 30px; margin-bottom: 30px;">
<div class="card" style="width: 100%; height: 100%;">

<!-- CARD HEADER -->
<div class="card-header" style="margin: 0px;">
Header stuff
</div>

<!-- CARD BODY -->
<div class="card-body" style="cursor: pointer;">
<div class="row">
<div class="col">
<h6 class="card-title">This is a longer description that will span 2 rows making things not line up right between cards</h6>
</div>
</div>

<!--<div class="d-flex align-items-center">-->
<div class="container orangeRedClass" style="background-color: orangered">
<div class="row">
<div class="col-4">
Starts On:
</div>
<div class="col">
1/1/2020
</div>
</div>
<div class="row">
<div class="col-4">
Ends On:
</div>
<div class="col">
12/31/2020
</div>
</div>
<div class="row">
<div class="col-4">
#:
</div>
<div class="col">
10
</div>
</div>
</div>
<!--</div>-->
</div>

<!-- CARD FOOTER -->
<div class="card-footer">
Footer stuff here
</div>

</div>
</div>

</div>
</div>
</div>

关于javascript - 将 div 对齐到 Bootstrap4 卡体的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55976464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com