css - 如何在没有绝对位置的情况下将我的(引导)元素带到列的底部?
问题描述
我正在处理 3 列,底部有图标。你可以在这个网站的底部看到它们:https ://matiny.github.io/
我想将图标直接带到每个灰色框的底部而不使用position absolute
(这是我目前正在使用的)。但是,没有absolute
,我不知道如何将所有 3 推到底部。默认情况下,它们都依赖于height
父级。
我试过使用flex
,但我不确定如何在这里应用它。Position absolute
导致手机出现min-height
问题。
这是一bootstrap
排,HTML
里面有 3 个这样的元素......
.gallery {
padding: 2.5rem 0;
}
.gallery h1 {
font-size: 3rem;
padding: 1.5% 0;
}
.gallery .app-box {
position: relative;
min-height: 31rem;
background-color: #ebedf0;
}
.gallery .app-box img {
width: 100%;
}
.gallery .app-box .caption {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.gallery .app-box .name,
.gallery .app-box .description {
padding: 1rem;
color: #0f1a30;
font-weight: 700;
}
.gallery .app-box .name {
font-size: 1.5rem;
padding-bottom: 0;
}
.gallery .app-box .description {
opacity: 0.5;
}
.gallery .app-box .icons {
height: 100%;
width: 100%;
opacity: 0.5;
padding-bottom: 1rem;
}
.gallery .app-box .icons img {
width: 15%;
margin: 0 0.25rem;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<section class="gallery">
<div class="col-md-4 col-12">
<a href="https://matiny.github.io/gta6/">
<figure class="app-box">
<img src="https://matiny.github.io/images/jpgs/gallery-gta.jpg" alt="">
<figcaption class="name">
GTA UI UPGRADES
</figcaption>
<div class="caption">
<figcaption class="description">GTA Online is very detailed, but the details are presented in a confusing way. <br> I came up with various menus which are simpler to use, while maintaining the same complex functions.
</figcaption>
<div class="icons">
<img src="https://matiny.github.io/images/svgs/icon-js.svg" alt="">
<img src="https://matiny.github.io/images/svgs/icon-react.svg" alt="">
<img src="https://matiny.github.io/images/svgs/icon-sass.svg" alt="">
</div>
</div>
</figure>
</a>
</div>
</section>
解决方案
父母(对我来说是卡片主体)应该有display : flex
......在里面,你可以让mt-auto
类自动设置margin-top......
下面的代码片段来自我不久前做的代码,它可以帮助你的情况
.card-body {
display: flex;
flex-direction: column;
text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-4 d-flex">
<div class="card">
<img class="card-img-top img-fluid" src="http://via.placeholder.com/400x300" alt="Card image">
<div class="card-body d-flex flex-colum">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<a href="#" class="btn customBtn mt-auto">Read More</a>
</div>
</div>
</div>
<div class="col-12 col-sm-4 d-flex">
<div class="card">
<img class="card-img-top img-fluid" src="http://via.placeholder.com/400x300" alt="Card image">
<div class="card-body d-flex flex-colum">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a href="#" class="btn customBtn mt-auto">Read More</a>
</div>
</div>
</div>
<div class="col-12 col-sm-4 d-flex">
<div class="card">
<img class="card-img-top img-fluid" src="http://via.placeholder.com/400x300" alt="Card image">
<div class="card-body d-flex flex-colum text-center">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
<a href="#" class="btn customBtn mt-auto">Read More</a>
</div>
</div>
</div>
</div>
</div>
推荐阅读
- python - 如何找到多个文本文件中数字的平均值?
- css - 使用 CSS 制作 3D 画框效果
- android - Android TextView 水平滚动延迟
- vba - 错误消息:“操作值必须是数字”,在创建新的 JIRA 问题时
- r - 如何获得每个因子的 p 值,而不是零膨胀泊松模型中每个因子水平的 p 值?
- php - 查询缓存类型在 X-cart 应用程序中显示为 ON/not
- javascript - 将元数据添加到 Stripe 客户对象
- sql - T-SQL 获取连续行
- reactjs - 如何让 create-react-app 在脚本路径中包含前导点?
- c++ - 使用 Windows Sensor API 从多个传感器检索信息