css - Bootstrap:收缩列
问题描述
我有一个带有树列的表。我希望“小”列尽可能小。
我认为col-auto 会这样做:
使用 col-{breakpoint}-auto 类根据其内容的自然宽度调整列的大小。
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered">
<tr>
<td>big1</td>
<td class="col-auto">small</td>
<td>big2</td>
</tr>
</table>
如何缩小“小”列并将空间留给其他列?
解决方案
类col-auto
使用flex
规则,但您的父容器未定义为display: flex
. 侧标签td
应设置为flex: 1
.
.table.table-bordered tr {
display: flex;
}
.table.table-bordered tr td:nth-child(1),
.table.table-bordered tr td:nth-child(3) {
flex: 1;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered">
<tr>
<td>big1</td>
<td class="col-auto">small</td>
<td>big2</td>
</tr>
</table>
推荐阅读
- java - Opengl java弹跳实体
- python - 如何使用 Python 遍历 xml 路径字符串(表行 -- tr[1]、tr[2]、tr[3]...)?
- hyperledger-fabric - Composer Rest Server 不返回模型文件中注释的内容
- android - 在工具栏中显示进度条
- r - R聚合多行
- plugins - 如何通过插件更新系统锁定的字段?
- google-cloud-platform - 自动完成每个字符的使用
- php - PHP循环基于引导列的行号
- video - D3D 纹理到 NVIDIA 媒体基础编码器
- css - 添加图像的问题 - list-style-image