html - 无法在标签中居中输入

标签 html css twitter-bootstrap

我正在使用 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/

相关文章:

javascript - 灯箱不会触发 onclick

javascript - Jquery在文本元素后面添加带有背景的div

javascript - 无法加载资源 404(未找到)- 文件位置错误?

html - 内容在 div 内折叠

ios - iOS 上的 Google +1 按钮

python - 如何从没有很多结构的抓取页面中提取数据

html - 如何管理 css 媒体查询网格列

html - 你怎么能让 Bootstrap 3 选项卡上的文本溢出?

css - 如何在图像上获取文本,并且也是响应式的?

javascript - Bootstrap 模态显示但没有文本可见