【问题标题】:Bootstrap rows and form-inlines changing width of inputs引导行和表单内联改变输入的宽度
【发布时间】:2013-11-07 14:09:43
【问题描述】:

我希望表单的每行包含三个控件。但是每一行中控件的宽度是不同的(不太准确)。我必须总是使用列吗?这是css的常规行为吗?有时 css 对我来说就像一个迷宫

这是我目前所拥有的:

bootply

<form action="" method="post" role="form" class="form-inline">
    <div class="container">
        <div class="row">
            <div class="form-group">
                <label for="id_firstname">First Name</label>
                <input type="text" name="firstname" class="form-control" id="id_firstname">
            </div>
            <div class="form-group">
                <label for="id_middlename">Middle Name</label>
                <input type="text" name="middlename" class="form-control" id="id_middlename">
            </div>
            <div class="form-group">
                <label for="id_lastname">Last Name</label>
                <input type="text" name="lastname" class="form-control" id="id_lastname">
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="form-group">
                <label for="id_address">Address</label>
                <input type="text" name="address" class="form-control" id="id_address">
            </div>
            <div class="form-group">
                <label for="id_postalcode">Postal Code</label>
                <input type="text" name="postalcode" class="form-control" id="id_postalcode">
            </div>
            <div class="form-group">
                <label for="id_city">City</label>
                <input type="text" name="city" class="form-control" id="id_city">
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="form-group">
                <label for="id_telephone">PHone</label>
                <input type="text" name="phone" class="form-control" id="id_telephone">
            </div>
            <div class="form-group">
                <label for="id_mobile">Mobile</label>
                <input type="text" name="mobile" class="form-control" id="id_mobile">
            </div>
            <div class="form-group">
                <label for="id_email">E-mail</label>
                <input type="text" name="email" class="form-control" id="id_email">
            </div>
        </div>
    </div>
</form>

抱歉,您只想要链接。我还用 .col-md-4 包裹了每个 .form-group,但输入的宽度仍然彼此不同

【问题讨论】:

  • 你为什么犹豫使用 col-md-...?这会更好或使用 html table
  • 编辑了我的帖子。我确实使用了它,但我仍然得到不同的宽度。

标签: css forms twitter-bootstrap


【解决方案1】:

来自Inline Forms 上的引导文档

需要自定义宽度:在 Bootstrap 中,输入、选择和文本区域默认为 100% 宽。要使用内联表单,您必须在其中使用的表单控件上设置宽度。


如果您希望所有输入的大小相同,只需应用以下 css

.form-group {
    width: 300px;
}
.form-group input {
    width: 300px;
}

bootply with css


通过将col-md-4 类添加到每个组来固定每个表单组的宽度,如下所示:

<div class="form-group col-md-4">
    <label for="id_telephone">Phone</label>
    <input type="text" name="phone" class="form-control" id="id_telephone">
</div>

bootply with classes

【讨论】:

    猜你喜欢
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 2015-11-25
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多