如何强制标签向左对齐?

时间:2018-08-06 13:50:05

标签: css text-align

我想给我的文本字段添加一个标签,该标签应与左侧对齐:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>

  <table style="width:100%; height:100%">
    <tbody>
      <tr>
        <td style="padding:15px" valign="top">
          <div class="tab-content product_single">
            <section class="content-header" style="margin-bottom:20px">
              <h1 style="float:left;margin-bottom:30px">New Entry</h1>
            </section>
            <section class="content">
              <div class="form-group">
                <form name="form" method="post">
                <div id="form"><div><label for="form_username" class="required">Username</label><input id="form_username" name="form[username]" required="required" class="form-control" type="text"></div><div><label for="form_email" class="required">Email</label><input id="form_email" name="form[email]" required="required" class="form-control" type="text"></div><div><button type="button" id="form_cancel" name="form[cancel]" class="form-btn btn btn-default pull-right close_sidebar close_h">Cancel</button></div><div><button type="submit" id="form_save" name="form[save]" class="form-btn btn btn-info pull-right" style="margin-right:5px">Save</button></div><input id="form__token" name="form[_token]" value="" type="hidden"></div>
                </form>
              </div>
            </section>
          </div>
        </td>
      </tr>
    </tbody>
  </table>


 

由于我的应用程序中有一些样式,因此我的第一个标签总是贴在中间,而我无法弄清楚任何样式,这是什么原因。因此,我尝试使用text-align:lefttext-align:left!important之类的所有方法,但是无论我做什么,它都只会停留在中心位置。

enter image description here

1 个答案:

答案 0 :(得分:2)

您需要清除标题上的浮动内容-不知道为什么要浮动它。也不要使用表格进行布局-它会否定引导程序的使用,并且语义上不正确

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet" />

<div class="tab-content product_single">
  <section class="content-header" style="margin-bottom:20px">
    <h1 style="float:left;margin-bottom:30px">New Entry</h1>
  </section>
  

  <section class="content" style="clear:left">  <!-- I have added this style attribute or you could just remove the float from the heading -->
  
  
    <div class="form-group">
      <form name="form" method="post">
        <div id="form">
          <div><label for="form_username" class="required">Username</label><input id="form_username" name="form[username]" required="required" class="form-control" type="text"></div>
          <div><label for="form_email" class="required">Email</label><input id="form_email" name="form[email]" required="required" class="form-control" type="text"></div>
          <div><button type="button" id="form_cancel" name="form[cancel]" class="form-btn btn btn-default pull-right close_sidebar close_h">Cancel</button></div>
          <div><button type="submit" id="form_save" name="form[save]" class="form-btn btn btn-info pull-right" style="margin-right:5px">Save</button></div><input id="form__token" name="form[_token]" value="" type="hidden"></div>
      </form>
    </div>
  </section>
</div>