简体   繁体   English

表单内的HTML标签和输入框未对齐

[英]HTML label and input box inside form not align

group to align a label and an input box. 组以对齐标签和输入框。 The idea is to put the label and the input box in different lines. 想法是将标签和输入框放在不同的行中。 The code snippets are like: 代码片段如下:

<form>
    <div class="form-group">
        <label for="input">Please enter names, separated by space:</label>
            <div>
                <div class="col-xs-8">  
                    <input type="text" class="form-control" id="input" placeholder="Enter up to 10 names to search" ng-model="vm.searchRaw">
                </div>
                <div class="block-align-right">
                    <button class="btn btn-primary" style="width: 120px" ng-click="vm.search()" ng-disabled="vm.notEntered()">Search</button>
                </div>
            </div>
    </div>
</form>

The divs inside the form group is mainly to align the input box and the button to one line. 表单组中的div主要是将输入框和按钮对齐到一行。 Now the problem is: the left edge of the label and the left edge of the input box don't align; 现在的问题是:标签的左边缘和输入框的左边缘未对齐; the input box shifts to the right a bit. 输入框向右移动一点。 Without using padding how can I fix this? 如果不使用填充,该如何解决呢? Or is it built in for the form-group? 还是为表单组内置的? Thanks! 谢谢!

Use this type 使用这种类型

Working JS Fiddle 工作的JS小提琴

HTML: HTML:

<div>
      <label>Name:</label><input type="text">
      <label>Email Address:</label><input type = "text">
      <label>Description of the input value:</label><input type="text">
  </div>

CSS: CSS:

label{
    display: inline-block;
    float: left;
    clear: left;
    width: 250px;
    text-align: right;
}
input {
  display: inline-block;
  float: left;
}

Seems like you are using bootstrap. 似乎您正在使用引导程序。 Just modify the <label> line as follows: 只需修改<label>行,如下所示:

<label for="input" class="col-xs-12">Please enter names, separated by space:</label>

Add class to label. 将类别添加到标签。 like: 喜欢:

<label class="col-xs-10" for="input">Please enter names, separated by space:</label>

Will solve your issue. 将解决您的问题。

Because bootstrap class will add padding-left:15px . 因为bootstrap类将添加padding-left:15px

Check image below. 检查下面的图像。

在此处输入图片说明

Working Fiddle 工作小提琴

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

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