Twitter Bootstrap 3 - 嵌套表单-水平响应式设计问题 [英] Twitter Bootstrap 3 - Nested Form-Horizontal Responsive Design Issue

查看:42
本文介绍了Twitter Bootstrap 3 - 嵌套表单-水平响应式设计问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多 Twitter Bootstrap 3 表单-水平样式表单,它们嵌套在各个页面的列中.通常,当标签和输入有足够的空间并排显示时,它们就会这样做,否则标签会出现在输入上方.一切都很好,正如预期和期望的那样.

但是,当表单开始时没有太多宽度时,假设表单位于使用 Bootstrap 12 列网格系统的 12 列中的 3 列宽的外部列中,我看到标签被切断并且消失在输入下方,而不是看到标签在输入上方移动.澄清一下,如果标签在上方,那么表单中的宽度将足以让所有内容都可见.

您可以在此处看到发生这种情况的简化示例,该示例使用了 Twitter Bootstrap 3 文档中的表单横向示例:http://jsfiddle.net/BF4ZK/

在上面显示的示例中,电子邮件"和密码"标签被截断而不是移到输入上方.代码如下:

<头><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"/><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script><script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script><身体><div class="容器"><div class="row"><!-- 总是有两个并排的列--><div class="col-xs-3"><!-- 在左栏中放置一个表单 - 来自 Bootstrap 官方表单水平示例的精确副本--><form class="form-horizo​​ntal" role="form"><div class="form-group"><label for="inputEmail3" class="col-sm-2 control-label">电子邮件</label><div class="col-sm-10"><input type="email" class="form-control" id="inputEmail3" placeholder="Email">

<div class="form-group"><label for="inputPassword3" class="col-sm-2 control-label">密码</label><div class="col-sm-10"><input type="password" class="form-control" id="inputPassword3" placeholder="密码">

<div class="form-group"><div class="col-sm-offset-2 col-sm-10"><div class="checkbox"><标签><输入类型=复选框">记得我

<div class="form-group"><div class="col-sm-offset-2 col-sm-10"><button type="submit" class="btn btn-default">登录</button>

</表单>

<div class="col-xs-9">3 列向左,9 列向右.

如果本例中的表单被移动到页面右侧的 9 列部分,而不是页面左侧较小的 3 列部分,那么它会按预期响应,并且通常会显示侧边 -如果没有足够的空间,可以并排或移动到上方.我尝试了很多变体,包括多个 col-xs、col-sm、col-md、col-lg,甚至在没有表单水平和标签控件的情况下滚动我自己的解决方案,在表单周围添加行,更改 Bootstraps 最大宽度,等等.事情似乎相当一致,因为如果表单位于页面的更宽部分,它会按预期响应.

有没有人遇到过这种情况或知道解决方案?这似乎是 Twitter Bootstrap 3 错误,但我可能做错了一些事情,因此欢迎任何更正.我有一个解决方法,强制表单水平始终保持垂直,但我真的很想让表单水平在 Twitter Bootstrap 中按照预期的方式工作.

非常感谢您提供任何反馈.

解决方案

任何时候在另一列中嵌套一列,都必须用新行包裹:

<!-- 在左栏中放置一个表单 - 来自 Bootstrap 官方表单水平示例的精确副本--><form class="form-horizo​​ntal" role="form"><div class="form-group"><label for="inputEmail3" class="col-sm-2 control-label">电子邮件</label><div class="row"><div class="col-sm-10"><input type="email" class="form-control" id="inputEmail3" placeholder="Email">

一旦我添加了它,标签和表单字段就会堆叠起来.

I have a number of Twitter Bootstrap 3 form-horizontal style forms that are nested in columns on various pages. Generally, when there is enough room for the labels and inputs to appear side-by-side, then they do so, else the label appears above the input. All well and good, and as expected and desired.

However, when there is not much width available to start with for the form, say the form is inside an outer columns that's 3 of 12 wide using the Bootstrap 12 column grid system, I'm seeing the labels being cut off and disappearing underneath the inputs instead of seeing the labels moving above the inputs. To clarify, if the labels were above then there would be enough width in the form for everything to be visible.

You can see a simplified example of this occurring here, which uses the form-horizontal example found in the Twitter Bootstrap 3 documentation: http://jsfiddle.net/BF4ZK/

In the example shown above, the "Email" and "Password" labels are truncated instead of moving above the inputs. The code for this is as follows:

<!DOCTYPE html><html lang="en">
<head>
    <meta name="viewport"  content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css"       href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
    <script                type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
    <script                type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <div class="row">

            <!-- always have two side-by-side columns -->
            <div class="col-xs-3">

                <!-- place a form in the left column - exact copy from Bootstrap official example of form-horizontal -->
                <form class="form-horizontal" role="form">
                  <div class="form-group">
                    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
                    <div class="col-sm-10">
                      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                      <div class="checkbox">
                        <label>
                          <input type="checkbox"> Remember me
                        </label>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                      <button type="submit" class="btn btn-default">Sign in</button>
                    </div>
                  </div>
                </form>        

            </div>

            <div class="col-xs-9">
                3 col to left, 9 col to right.
            </div>

        </div>
    </div>
</body>

If the form in this example were moved to be in the 9 column section on the right of the page instead of the smaller 3 column section on the left of the page then it would behave responsively as expected and would typically display side-by-side or move above if there is not enough room. I've tried a lot of variations including multiple col-xs, col-sm, col-md, col-lg and even rolling my own solution without form-horizontal and label controls, adding rows around the form, changing Bootstraps max widths, and so on. Things seem to be fairly consistent in that the form acts responsively as expected if it lives in a wider section of the page.

Has anyone encountered this before or know of a solution? This appears to be a Twitter Bootstrap 3 bug but I may be doing something incorrectly so would welcome any corrections. I have a workaround that forces form-horizontals to always be vertical but I'd really like to get form-horizontal working the way it is intended in Twitter Bootstrap.

Many thanks in advance for any feedback.

解决方案

Anytime you nest a column within another column, you must have that wrapped with a NEW row:

<div class="col-xs-3">
<!-- place a form in the left column - exact copy from Bootstrap official example of form-horizontal -->
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="row">
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">

Once I added that, the labels and form fields stacked.

这篇关于Twitter Bootstrap 3 - 嵌套表单-水平响应式设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆