css - 将 html 输入大小/最大长度与 Bootstrap 的表单控件一起使用

标签 css html forms twitter-bootstrap input

我在尝试使用 html5 的表单大小/最大长度和 Bootstrap 时遇到了一个有趣的问题。

大小被 boostrap 的 .form-control 类覆盖,但删除它会导致输入失去其样式。

码笔:http://codepen.io/rkhayat/pen/JoeBqx

谢谢

 <div class="container">
    <div class="form-group">
        <p>Phone</p><input class="form-control" id="inputPhone" maxlength=
        "3" name="phone" required="required" size="3" title="" type="tel"
        value="">
    </div>
</div><!--with form-control-->

<div class="container">
    <p>Notice that removing form-control loses ALL styling, but keeps the
    size from html size input</p>
</div>

<div class="container">
    <div class="form-group">
        <p>Phone</p><input id="inputPhone" maxlength="3" name="phone"
        required="required" size="3" title="" type="tel" value="">
    </div>
</div><!--without form-control-->

编辑:研究我发现了这个http://getbootstrap.com/css/#column-sizing

实现了 bootstrap 推荐的修复,感觉像是一个 hack。

  <div class="col-xs-4">
            <div class="form-group">
                <p>Phone</p>
                <div class="col-xs-3">
                    <input type="tel" name="phone" class="form-control" value="" size="3" maxlength="3" required="required" title="">
                </div>

                <div class="col-xs-3">
                    <input type="tel" name="phone" class="form-control" value="" size="3" maxlength="3" required="required" title="">
                </div>


                <div class="col-xs-4">
                    <input type="tel" name="phone" class="form-control" value="" size="4" maxlength="4" required="required" title="">
                </div>
            </div>
        </div>

最佳答案

我使用 cols 来调整大量表单元素(尤其是整个 form-group)的宽度。我只是称它们为 class="skinny" 然后添加:

.skinny{
padding-left:0;
}

到目前为止对我来说效果很好。没有尝试过 maxlength 但这解决了我主要的布局问题!

关于css - 将 html 输入大小/最大长度与 Bootstrap 的表单控件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29105846/

相关文章:

html - 后台页面不显示

python - 如何从表单django发送电子邮件

html - CSS 将元素填充到网格中(并将它们居中)

html - 使用css定位img元素

html - 使用溢出后下拉菜单不显示?

multithreading - delphi中的DLL、表单和线程(合一)问题

c# - 获取子进程的形式

html - 基于 CSS 的网站无法在 Internet Explorer 上运行

JavaScript FocusEvent relatedTarget 属性在 firefox 中不起作用

jQuery 隐藏和显示 Div