【问题标题】:In bootstrap css, I want to use form elements the resize nicely with the grid layout在引导 css 中,我想使用表单元素来很好地调整网格布局
【发布时间】:2015-01-30 15:16:56
【问题描述】:

我在这里遇到了问题。如果我保留 form-control 类应用,我可以在键入时看到密码字符(它设置字体前景和背景),但它还将宽度设置为 100%,这使得输入控件太宽。如果它删除了form-control 类,那么我就看不到输入,并且我失去了文本中漂亮的填充效果。有没有干净的方法来解决这个问题?

旧的解决方法是在输入中添加 style="width:100px"。不过,这会破坏小屏幕。我真的需要网格来代替。

            <div>
                <div class="col-sm-4"></div>
                <div class="col-sm-4">
                    <input 
                        name="sp" type="password" 
                        class="form-control" 
                        required ng-minlength="9" ng-maxlength="255" />
                </div>
                <div class="col-sm-4"></div>
            </div>

参考:http://getbootstrap.com/css/#code

这是一个很好的指南,但似乎所有示例都使用完全展开的输入元素,其中两侧都有另一个可见的输入元素。我在网格中使用空元素来占用空间(以居中)输入。 http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-forms.php

【问题讨论】:

  • "我在网格中使用空元素来占用空间" 不要那样做。改用偏移类。请参阅github.com/twbs/bootlint/wiki/W009 另外,您的示例缺少&lt;div class="row"&gt;

标签: css twitter-bootstrap


【解决方案1】:

在这个例子中,为什么不对输入字段应用max-width css 规则。

@media (min-width: 786px) {
    input[name="sp"] {
        min-width: 100px;
    }
}

如果您将此规则包装在媒体查询中,您将能够控制小型、中型和大型布局的大小,同时确保它在移动设备上仍然看起来不错。

除了使用空的&lt;div class="col-sm-4"&gt;&lt;/div&gt;,你也可以这样做

<div class="col-sm-4 col-sm-offset-4"></div>

【讨论】:

  • 我尝试使用 max-width (它需要更小).. css 检查器仍然向我显示(使用表单控制)实际宽度远大于它需要的宽度。这导致它左对齐。
  • 这就是这样做的方法。我建议在您的答案中添加display: inline。 Bootstrap 显示:block,这是导致左对齐(而不是居中)的扩展效果的原因。
猜你喜欢
  • 2021-05-19
  • 2022-01-18
  • 1970-01-01
  • 2022-01-20
  • 2020-06-30
  • 1970-01-01
  • 2019-10-04
  • 2023-03-17
  • 2021-01-30
相关资源
最近更新 更多