简体   繁体   English

引导程序格式化列对齐问题

[英]Bootstrap formatting columns align issue

Working html code: UPDATED 工作的html代码:已更新

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" rel="stylesheet"/>

<form class="form-horizontal ng-pristine ng-valid ng-valid-required" role="search">
    <div class="row">
        <div class="form-group col-md-12">
            <label class="control-label col-md-6" for="inputEmail">Employee Name:</label>
              <div class="col-md-4">
                <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
              </div>
              <div class="col-md-2">
                <button class="form-control btn btn-info">Hello world</button>
              </div>
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-12">
            <label class="control-label col-md-6" for="inputEmail">My Owning Location:</label>
            <div class="col-md-6">
                <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
            </div>
        </div>
    </div>
</form>

How can I format my lable/input field align? 如何格式化标签/输入字段对齐? below is html along with screen shots how it renders after I run the page: 下面是html以及运行页面后如何呈现的屏幕截图:

what I want the output to be is: 我想要的输出是:

  Employee Name: XXXXXXXXXXXXX My Owning Location: XXXXXXXXXXXXX Manager Name: XXXXXXXXXXXXX 
 <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
 <link href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" rel="stylesheet"/>
<form class="navbar-form form-horizontal ng-pristine ng-valid ng-valid-required" role="search" style="padding:0">
    <div class="col-md-12" style="margin: 10px;">

        <div class="form-group">
            <label class="control-label col-md-6" for="inputEmail">Employee Name:</label>
            <div class="col-lg-6">
                <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
            </div>
        </div>
    </div>

    <div class="col-md-12" style="margin: 10px;">
        <div class="form-group">
            <label class="control-label col-md-6" for="inputEmail">My Owning Location:</label>
            <div class="col-lg-6">
                <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
            </div>
        </div>
    </div>
</form>

在此处输入图片说明

I added the corresponding row-fluid to reset the grid for the label and input boxes. 我添加了相应的行流体以重置标签和输入框的网格。 https://jsfiddle.net/gyod/7mgtfk3k/4/ Here is one example. https://jsfiddle.net/gyod/7mgtfk3k/4/这是一个示例。

<form class="container row-fluid navbar-form form-horizontal ng-pristine ng-valid ng-valid-required" role="search" style="padding:0">
  <div class="col-md-12" style="margin: 10px;">

    <div class="row-fluid">
        <label class="control-label col-xs-3" for="inputEmail">Employee Name:</label>
        <div class="col-xs-9">
            <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
        </div>
    </div>
</div>

<div class="col-md-12" style="margin: 10px;">
    <div class="row-fluid">
        <label class="control-label col-xs-3" for="inputEmail">My Owning Location:</label>
        <div class="col-xs-9">
            <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
        </div>
    </div>
  </div>
</form>

I've solved this for you and created a codepen editor for this. 我已经为您解决了这个问题,并为此创建了一个代码笔编辑器

The code will look lke, 该代码看起来像,

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" rel="stylesheet"/>

<form class="form-horizontal ng-pristine ng-valid ng-valid-required" role="search">
    <div class="row">
        <div class="form-group col-md-12">
            <label class="control-label col-md-6" for="inputEmail">Employee Name:</label>
            <div class="col-md-6">
                <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
            </div>
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-12">
            <label class="control-label col-md-6" for="inputEmail">My Owning Location:</label>
            <div class="col-md-6">
                <input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
            </div>
        </div>
    </div>
</form>

What I've done is wrap your form group elements into row classes which makes children appear in a row, and for the form-group classed element I've set it to col-md-12 which does make it full width of the grid. 我要做的是将表单组元素包装到row类中,使子代出现在一行中;对于form-group分类元素,我将其设置为col-md-12 ,这确实使其整个网格宽度。

I've also removed navbar-form class from your form element 我还从您的form元素中删除了navbar-form

I've heard my colleague (front-end guy) saying to use row and child elements of them as grid columns as a standard, i don't know the validity of that statement, but it works for real! 我已经听到我的同事(前端人员)说要使用它们的row和子元素作为网格列作为标准,我不知道该声明的有效性,但它确实有效! :) :)

And a note, do not use inline styles which makes things lot worse and untraceable while looking at the code itself. 请注意,请勿使用内联样式,这会导致在查看代码本身时情况变得更糟且难以追踪。

Try to put the label tag inside div class="col-xs-6". 尝试将标签标记放在div class =“ col-xs-6”内。 Then you can get a horizontal aligned elements of each div. 然后,您可以获取每个div的水平对齐元素。

If you want to make it properly align, you can set default width for the label and use bootstrap built-in class for alignment. 如果要使其正确对齐,则可以设置标签的默认宽度,并使用bootstrap内置类进行对齐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM