我正在使用 Bootstrap 的单选按钮并修改样式。我似乎无法让这些按钮上的文字垂直居中。我试过将内容边距设置为 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>
关于html - 无法在标签中居中输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50763315/