twitter-bootstrap Bootstrap .form-horizo​​ntal 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21863199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:05:05  来源:igfitidea点击:

Bootstrap .form-horizontal not working

htmltwitter-bootstraptwitter-bootstrap-3

提问by Stefanos Vakirtzis

I am a first-try bootstrap guy. The thing i want to achieve is to have labels and inputs same line nice and clean.

我是第一次尝试引导程序的人。我想要实现的事情是让标签和输入相同的线条漂亮干净。

Anyone can explain me why in the below example labels are still above inputs? Am i doing something wrong?

任何人都可以解释为什么在下面的示例中标签仍然高于输入?难道我做错了什么?

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta application-name="Test-System">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

    <!-- Bootstrap Latest compiled and minified JavaScript -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

    <!-- jQuery UI from Google CDN -->
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
    <title></title>
</head>
<body>

    <form class="form-horizontal">
        <div class="control-group">
            <label for="input1" class="control-label">Label</label>
            <div class="controls">
                <input id="input1" type="text">
            </div>
        </div>

        <div class="control-group">
            <label for="input2" class="control-label">Label</label>
            <div class="controls">
                <input id="input2" type="text">
            </div>
        </div>
    </form>

     <!-- jQuery from Google CDN -->
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
     <!-- jQuery UI from Google CDN -->
     <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</body>
</html>

回答by Chris

<div class="controls">
                <label for="input1" class="control-label">Label</label>
                <input id="input1" type="text">
 </div>

Is this what you are looking for?

这是你想要的?

EDITHorizontal label from outside of input's div.

从输入的 div 外部编辑水平标签。

    <div class="control-group">
        <label for="input1" class="control-label col-sm-2">Label</label>
        <div class="controls col-sm-10">
            <input id="input1" type="text">
        </div>
    </div>

回答by Ankush Ganatra

Try this gem. It worked with ease for me.

试试这个宝石。它对我来说很容易。

gem 'simple_form_bootstrap3'

宝石'simple_form_bootstrap3'

Need to replace form_for with "horizontal_form_for"

需要用“horizo​​ntal_form_for”替换form_for