html – 为什么表单组在Bootstrap中有负余量?

前端之家收集整理的这篇文章主要介绍了html – 为什么表单组在Bootstrap中有负余量?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个非常简单的代码使用Bootstrap 3:
  1. <html>
  2. <body>
  3. <main class="container" role="main">
  4. <form class="simple_form form-horizontal">
  5. <div class="form-group text required campaign_url">
  6. <label class="text required control-label" for="campaign_url"><abbr title="required">*</abbr> Url</label>
  7. <textarea class="text required form-control" name="campaign[url]" id="campaign_url"></textarea>
  8. </div>

它看起来像这样:

注意标签和投入是否粘在左边.检查那些元素我发现这个:

  1. .form-horizontal .form-group {
  2. margin-left: -15px;
  3. margin-right: -15px;
  4. }

为什么在那里?我知道删除它是微不足道的,但它让我想知道我使用Bootstrap的方式是错误的.我该怎么用?

解决方法

它正在发生,因为你使用的是form-horizo​​ntal,这意味着与col-*一起被用作布局.从Bootstrap文档:

Use Bootstrap’s predefined grid classes to align labels and groups of form controls in a horizontal layout by adding .form-horizontal to the form (which doesn’t have to be a ). Doing so changes .form-groups to behave as grid rows,so no need for .row.

所以如果你简单地删除形状水平的负边距消失.

http://codeply.com/go/QQnqgfKv9v

猜你在找的HTML相关文章