gpt4 book ai didi

html - 如何水平居中行内 block 元素

转载 作者:行者123 更新时间:2023-11-28 04:25:11 25 4
gpt4 key购买 nike

我有 4 个 Bootstrap 按钮。我希望它们成一直线并水平居中。这是html(看起来很复杂,但确实很重复):

    <div class="[ col-xs-12 col-sm-6 ]">
<div class="[ form-group ]">
<input type="checkbox" name="fancy-checkbox-success-custom-icons" id="fancy-checkbox-success-custom-icons" autocomplete="off" />
<div class="[ btn-group ]">
<label for="fancy-checkbox-success-custom-icons" class="[ btn btn-success ]">
<span class="[ glyphicon glyphicon-plus ]"></span>
<span class="[ glyphicon glyphicon-minus ]"></span>
</label>
<label for="fancy-checkbox-success-custom-icons" class="[ btn btn-default active ]">
Nature
</label>
</div>
</div>
<div class="[ form-group ]">
<input type="checkbox" name="fancy-checkbox-info-custom-icons" id="fancy-checkbox-info-custom-icons" autocomplete="off" />
<div class="[ btn-group ]">
<label for="fancy-checkbox-info-custom-icons" class="[ btn btn-info ]">
<span class="[ glyphicon glyphicon-plus ]"></span>
<span class="[ glyphicon glyphicon-minus ]"></span>
</label>
<label for="fancy-checkbox-info-custom-icons" class="[ btn btn-default active ]">
History
</label>
</div>
</div>
<div class="[ form-group ]">
<input type="checkbox" name="fancy-checkbox-warning-custom-icons" id="fancy-checkbox-warning-custom-icons" autocomplete="off" />
<div class="[ btn-group ]">
<label for="fancy-checkbox-warning-custom-icons" class="[ btn btn-warning ]">
<span class="[ glyphicon glyphicon-plus ]"></span>
<span class="[ glyphicon glyphicon-minus ]"></span>
</label>
<label for="fancy-checkbox-warning-custom-icons" class="[ btn btn-default active ]">
Architecture
</label>
</div>
</div>
<div class="[ form-group ]">
<input type="checkbox" name="fancy-checkbox-danger-custom-icons" id="fancy-checkbox-danger-custom-icons" autocomplete="off" />
<div class="[ btn-group ]">
<label for="fancy-checkbox-danger-custom-icons" class="[ btn btn-danger ]">
<span class="[ glyphicon glyphicon-plus ]"></span>
<span class="[ glyphicon glyphicon-minus ]"></span>
</label>
<label for="fancy-checkbox-danger-custom-icons" class="[ btn btn-default active ]">
Entertainment
</label>
</div>
</div>
</div>
</div>

他们有自己的 CSS:

.form-group input[type="checkbox"] + .btn-group > label span {
width: 20px;
}

.form-group input[type="checkbox"] + .btn-group > label span:first-child {
display: none;
}
.form-group input[type="checkbox"] + .btn-group > label span:last-child {
display: inline-block;

}

.form-group input[type="checkbox"]:checked + .btn-group > label span:first-child {
display: inline-block;
}
.form-group input[type="checkbox"]:checked + .btn-group > label span:last-child {
display: none;
}

我想要做的是将这 4 个按钮显示在一行中并将它们水平居中。为什么这不起作用:

.form-group{
display: inline;

}

.container{
width: 100%;
margin-left: auto;
margin-right: auto;
display: block;
}

最佳答案

要使那些 .form-group 元素居中,请更改外部父元素...

<div class="[ col-xs-12 col-sm-6 ]">

<div class="[ col-xs-12 col-sm-6 ] text-center">

.text-center 类会将 text-align: center 分配给一个元素,并且 CSS 会将 inlineinline-block child 。

关于html - 如何水平居中行内 block 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42007828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com