首页 > 解决方案 > 无法在标签中居中输入

问题描述

我正在使用引导程序的单选按钮并修改样式。我似乎无法让这些按钮上的文本垂直居中。我尝试将内容边距设置为 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;
}

标签: htmlcsstwitter-bootstrap

解决方案


在标签上添加以下样式

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>


推荐阅读