javascript - 如何在卡片末尾对齐项目,垂直居中(使用引导程序 4)?
问题描述
我有一张很长的引导卡,上面有两行信息,一个标题和一个描述。然后我想要一个按钮,在这张卡片的右边,居中对齐。我当前的 html 按钮如下:
<div class="card card-body">
<h4>I'm a Card</h4>
<p>The button should be central, at the end of this card.</p>
<input type="button"
class="btn btn-outline-primary align-self-end"
value=".align-self-end">
</div>
代码笔: https ://codepen.io/Darlton29/pen/ZEbyNXe
如您所见,按钮位于卡片的底部,导致其高度增加。我怎样才能确保它总是在卡片的最后,在卡片的中心,并且不会增加卡片的高度?谢谢。
解决方案
添加flex-direction: row
到卡片,为内容添加一个容器,然后在按钮上更改align-self-end
为align-self-center
。
.mycard {
flex-direction: row!important;
justify-content: space-between;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-12">
<div class="card card-body mycard">
<div>
<h4>I'm a Card</h4>
<p>
The button should be central, at the end of this card.
</p>
</div>
<input type="button" class="btn btn-outline-primary align-self-center" value="Button">
</div>
</div>
</div>
推荐阅读
- sql - 雪花合并到删除是删除所有内容还是保留所有行?
- xml - Bash shell XML 到 CSV
- java - 保存时在 IntelliJ 中使用 google-java-format 格式化 Java 代码
- django - 如何使用 Postgres 提高 Django 的文本查询计数
- petsc - 与“扩展宏 'CHKERRQ”' 相关的编译错误
- python - 试图在不和谐 python bot 中使用多个 f 字符串不起作用
- java - mockito 测试通知用户某些事件的 void 方法不起作用
- html - 如何用虚线水平分隔两个文本即:text1............text2
- android - BottomNavigationView - Android Studio
- python - 在文件中替换和写入多个数据