bootstrap-4 - Bootstrap 4 个垂直堆叠的按钮,每个按钮都有两列左对齐文本
问题描述
在 Bootstrap 4 中,如何创建一个垂直堆叠的按钮列表,其中每个按钮包含两列左对齐文本?
解决方案
通过使用 btn-block,我能够将按钮扩展到其父容器的宽度:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<style>
button span {
float:left;
width: 50%;
text-align:left;
}
.btn-group-vertical {
justify-content: flex-start;
}
</style>
<h1 class="text-center">Two Left-Aligned Columns of Buttons in Bootstrap 4</h1>
<div class="container">
<div class="row">
<div class="col-2 col-sm-3 btn-group-vertical" role="group" aria-label="Vowels">
<button type="button" class="btn btn-sm btn-block btn-outline-dark border-light">
<span>text</span>
<span>text</span>
</button>
<button type="button" class="btn btn-sm btn-block btn-outline-dark border-light">
<span>more text</span>
<span>more text</span>
</button>
</div>
<div class="col-4 col-sm-3 btn-group-vertical" role="group" aria-label="Vowels">
<button type="button" class="btn btn-sm btn-block btn-outline-dark border-light">
<span>text</span>
<span>text</span>
</button>
<button type="button" class="btn btn-block btn-sm btn-outline-dark border-light">
<span>text</span>
<span>more text</span>
</button>
<button type="button" class="btn btn-block btn-sm btn-outline-dark border-light">
<span>text</span>
<span>even more text</span>
</button>
</div>
</div>
</div>
</body>
</html>
推荐阅读
- r - Faster way to run a regression on large Data
- python - 在列表开头插入元素
- java - 在给出结果之前迭代2个Arraylists检查不同类型的相等值?
- c++ - 是否可以创建模板类的向量并调用其函数?
- python - DefaultCredentialsError 提出“找不到文件”
- android - 我项目中的所有标签都返回 NULL,即使它包含值
- python-3.x - 如何使用 openpyxl 查找包含图像对象的单元格名称?
- javascript - Firestore/Rxfire - 查询集合然后订阅子 observables 数组
- python - 使用 python 脚本从设备获取 fps
- scala - 从函数返回函数时解读 Scala 错误