【问题标题】:Bootstrap 3 form checkbox label doesn't align with checkbox input in Chromium + FirefoxBootstrap 3 表单复选框标签与 Chromium + Firefox 中的复选框输入不对齐
【发布时间】:2014-08-15 10:33:23
【问题描述】:

在 chrome 和 firefox 中:

  • form-inline 导致标签向下移动,复选框和标签之间的空间比使用form-horizontal 时更窄。
  • form-horizontal 完美显示

Here's a demo in jsFiddle

这里有一些代码:

<form class="form-inline">
    <div class="checkbox">
        <label>
            <input type="checkbox"/> Test againn
        </label>
    </div>
</form>

截图如下:

有没有办法让两个浏览器中的复选框都正确对齐,或者我错过了什么?

【问题讨论】:

    标签: css twitter-bootstrap cross-browser twitter-bootstrap-3 alignment


    【解决方案1】:

    这实际上是所有浏览器中的一个问题(我已经测试过)

    这是一个屏幕截图 - 我添加了一个灰色边框,以便更容易判断它没有排队

    Here's a demo that reproduces the issue

    inline form 位于大于768px 的屏幕上时,会出现此问题。

    特别是,弄乱对齐的东西来自这个line of forms.less(它是与this commit一起引入的):

    float: none;
    

    天真地,将此值设置回float: left 似乎可以解决问题,但我不确定可能会出现什么其他问题。

    @media (min-width: 768px) {
        .form-inline .radio input[type="radio"], 
        .form-inline .checkbox input[type="checkbox"] {
            float: left;
            margin-right: 5px;
        }
    }
    

    Here's a working version of your code with these changes

    除此之外,您只需要调整 CSS

    【讨论】:

    【解决方案2】:

    radio or checkbox 更改为radio-inline or checkbox-inline 类后,我得到了我的作品

    http://jsfiddle.net/gn9Up/57/

    【讨论】:

    • 是的,但是如果您将浏览器的大小重新调整为 xs 大小,您的复选框将不会得到“垂直形式”,它将保持内联。
    【解决方案3】:

    就我而言,没有一个答案能解决问题。这就是我为正确对齐输入与标签所做的操作。 A 已将 2px 添加到边距顶部。在 bootstrap.css 中设置为 4px。将其设置为 6 像素“修复”问题。

    CSS

    input[type=checkbox] {
        margin: 6px 0 0;
    } 
    

    HTML

    <label class="checkbox-inline">
        <input type="checkbox" value=""> Label text
    </label>
    

    【讨论】:

    • 这个解决方案是唯一对我有用的!谢谢!!
    猜你喜欢
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 2019-11-18
    • 2021-02-25
    • 1970-01-01
    • 2019-03-09
    • 2014-08-29
    相关资源
    最近更新 更多