麻烦使标签中的输入居中

时间:2018-06-08 14:54:12

标签: html css twitter-bootstrap

我使用bootstrap的单选按钮并修改样式。我似乎无法将这些按钮上的文字垂直居中。我已经尝试将内容边距设置为0px并将align-content设置为居中并垂直对齐到中间。 text-align:center。我该怎么办?

这是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;
}

1 个答案:

答案 0 :(得分:2)

在标签上添加以下样式

display: flex;
align-items: center;
justify-content: center;

&#13;
&#13;
 


.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;
}
&#13;
  <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>
&#13;
&#13;
&#13;