html - 使用css在网格上等间距按钮
问题描述
我正在构建一个垂直间距有限的多列/多行按钮板。这是代码:
.container {
width: 100%;
display: flex;
flex-direction: column;
padding: 0px;
margin: 0px;
}
.title {
width: 100%;
text-align: center;
font-size: 18px;
font-weight: bold;
color: red;
height: 30px;
}
.buttons {
display: flex;
flex-direction: column;
height: 100px;
overflow-y: scroll;
}
.button-line {
display: flex;
flex-direction: row;
padding-bottom: 30px;
}
.button-line button {
width: 100%;
color: red;
font-size: 18px;
font-weight: bold;
text-align: center;
background-color: white;
border-radius: 4px;
padding: 20px;
}
.button-line button:hover {
color: white;
background-color: red;
}
<div class="container">
<div class="title">
OPTIONS
</div>
<div class="buttons">
<div class="button-line">
<div class="button">
<button>TEST BUTTON 1</button>
</div>
</div>
<div class="button-line">
<div class="button">
<button>TEST BUTTON 2</button>
</div>
<div class="button">
<button>TEST BUTTON 3</button>
</div>
</div>
<div class="button-line">
<div class="button">
<button>TEST BUTTON 4</button>
</div>
</div>
</div>
</div>
我的按钮没有在线条之间和按钮之间应用填充,而是在按钮上显示按钮。然后我需要行间距和按钮间距。都居中。
我在这里做错了什么?
解决方案
您正在强制显式height: 100px;
on .buttons
,您应该将其删除。如果您需要保持该高度但又希望 的内容.buttons
可滚动,则可以删除display: flex;
和flex-direction: column;
。更新了 jsfiddle:https ://jsfiddle.net/gnhb9Lu7/3/
.container {
width: 100%;
display: flex;
flex-direction: column;
padding: 0px;
margin: 0px;
}
.title {
width: 100%;
text-align: center;
font-size: 18px;
font-weight: bold;
color: red;
height: 30px;
}
.buttons {
height: 100px;
overflow-y: scroll;
}
.button-line {
display: flex;
flex-direction: row;
padding-bottom: 30px;
}
.button-line button {
width: 100%;
color: red;
font-size: 18px;
font-weight: bold;
text-align: center;
background-color: white;
border-radius: 4px;
padding: 20px;
}
.button-line button:hover {
color: white;
background-color: red;
}
<div class="container">
<div class="title">
OPTIONS
</div>
<div class="buttons">
<div class="button-line">
<div class="button">
<button>TEST BUTTON 1</button>
</div>
</div>
<div class="button-line">
<div class="button">
<button>TEST BUTTON 2</button>
</div>
<div class="button">
<button>TEST BUTTON 3</button>
</div>
</div>
<div class="button-line">
<div class="button">
<button>TEST BUTTON 4</button>
</div>
</div>
</div>
</div>
推荐阅读
- javascript - Datatable .row(0).data() 在初始化时未定义
- css - shinyjqui orderinput 按钮大小 [CSS]
- python - pandas 数据框中所有对的有效 k 最近邻
- r - R biglasso 结果与 hdm 或 glmnet 不匹配
- python - 如果字母“g”就在元音旁边,它也将被视为元音,如何去除字符串的元音?
- spring-boot - Istio 流量转移在内部通信中不起作用
- npm - npm 配置问题和安装 ganache-cli 和松露的错误
- javascript - 在 .innerHTML 中使用 '>' 会导致 HTML 语句过早关闭
- python - Pandas 按列表的总和分组 - 为 lstm 做准备
- sql - 为什么“联合所有”不符合我的预期?