html - 无法在标签中居中输入
问题描述
我正在使用引导程序的单选按钮并修改样式。我似乎无法让这些按钮上的文本垂直居中。我尝试将内容边距设置为 0px 并将对齐内容设置为居中,将垂直对齐设置为中间。还有文本对齐:居中。我该怎么办?
这是HTML:
<div class="root">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active form-check-label">
<input class="form-check-input" type="radio" checked autocomplete="off"> One
</label>
<label class="btn btn-default form-check-label">
<input class="form-check-input" type="radio" autocomplete="off"> Two
</label>
<label class="btn btn-default form-check-label">
<input class="form-check-input" type="radio" autocomplete="off"> Three
</label>
</div>
</div>
这是CSS:
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
.root .btn-group .btn {
border-radius: 0;
border-color: black;
background-color: white;
color: black;
box-shadow: none;
min-width: 90px;
height: 45px;
align-content: center !important;
vertical-align: middle !important;
text-align: center;
}
.root .btn-group .btn .form-check-input {
text-align: center;
vertical-align: middle;
margin: 0px;
}
.root .btn-group .btn.active {
background-color: black;
color: white;
}
解决方案
在标签上添加以下样式
display: flex;
align-items: center;
justify-content: center;
.root .btn-group .btn {
border-radius: 0;
border-color: black;
background-color: white;
color: black;
box-shadow: none;
min-width: 90px;
height: 45px;
align-content: center !important;
vertical-align: middle !important;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.root .btn-group .btn .form-check-input {
text-align: center;
vertical-align: middle;
margin: 0px;
}
.root .btn-group .btn.active {
background-color: black;
color: white;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="root">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active form-check-label">
<input class="form-check-input" type="radio" checked autocomplete="off"> One
</label>
<label class="btn btn-default form-check-label">
<input class="form-check-input" type="radio" autocomplete="off"> Two
</label>
<label class="btn btn-default form-check-label">
<input class="form-check-input" type="radio" autocomplete="off"> Three
</label>
</div>
</div>
推荐阅读
- javascript - 多个日期条目
- r - 在 R 中的表中,如何将一行中的所有值乘以一个值?
- google-apps-script - 在一张工作表上遇到多个 Google Apps 脚本问题
- javascript - Html5画布动画留下痕迹
- xml - 在 React Native 上使用 React-Native-RSS-Parse 在多个级别上解析 XML
- r - 根据其他行数据更新行
- c - 确定我们是否可以将“+”和“-”放在数字之间,以便结果可以被数字整除:我的错误在哪里?
- jquery - Bootstrap 4 在单击活动选项卡和页面上折叠导航选项卡
- c# - SQLDataReader 读取空值的问题
- python - Python Flair 可以解释不连续的注释吗?