简体   繁体   English

在同一行上对齐文本

[英]align text on the same line

I have an html which contains 1 label and 1 div box contains a text. 我有一个包含1个标签和1个div框包含文本的html。

<label class="control-label col-xs-2">Name:</label>
<div class="col-xs-10">
  <strong>Test</strong>
</div>

But they seem not located on the same line. 但是它们似乎不在同一条线上。 Here is the jsfiddle Could anyone help me how can I align them on the same line. 这是jsfiddle,有人可以帮助我如何将它们对齐在同一行上。

Thanks 谢谢

I see you are using bootstrap. 我看到你正在使用bootstrap。 Bootstrap already has default CSS for labels. Bootstrap已经具有用于标签的默认CSS。 so if you don't want that to happen remove the padding from the <label> element. 因此,如果您不希望这种情况发生,请从<label>元素中删除填充。

It will look like this: 它看起来像这样:

.form-horizontal .control-label {
    float: left;
    width: 160px;
    /* padding-top: 5px; */
    text-align: right;
}

Hope this helps, Cheers. 希望这会有所帮助,干杯。

Apply padding-top to the col-xs-10 in your CSS. padding-top应用于CSS中的col-xs-10

.col-xs-10 {
 padding-top: 5px;
}

Try this 尝试这个

<div class="form-horizontal" role="form">
  <div class="form-group">
    <label class="control-label col-xs-2">Name:</label>
    <div class="col-xs-10">
      <strong>Test</strong>
    </div>
  </div>
</div>

In bootstrap if you would like to have a horizontal form it is called inline. 在bootstrap中,如果您想使用水平形式,则称为内联。 So, if you change your "form-horizontal" to "form-inline" you will achieve that horizontal key/value pair. 因此,如果将“水平窗体”更改为“内联窗体”,则将实现该水平键/值对。 Below is the html that I changed to your code. 以下是我更改为您的代码的html。 I hope this is what you are looking for. 我希望这就是你要找的东西。

<div class="form-inline" role="form">
   <div class="form-group">
   <label for="control-label col-xs-12">Name:</label>
   <input type="text" class="form-control col-xs-10" id="control-label"placeholder="text here">           
   </div>
   </div>

In addition, you will notice that I have inserted an input tag. 此外,您会注意到我已经插入了输入标签。 This is what will allow site visitors to input the value. 这就是允许站点访问者输入值的原因。

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

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