css - Bootstrap col-sm-offset-2 未对齐表单中的按钮

标签 css ruby-on-rails twitter-bootstrap

为什么在此表单中 col-sm-offset-2 按钮“二”不与其上方的 col-sm-2 标签对齐?

form section

我使用空标签对其进行了蹩脚的修复(请参阅按钮“一”),但我想了解如何使用更清晰的代码并使其正确,以便我的所有表单中都没有 kludge 标签按钮。

<form class="form-horizontal" role="form" action="/company/create" method="post">

  <div class="form-group">
     <%= label_tag(:name, 'Company name:', :class => 'control-label col-sm-2') %>
     <div class="col-sm-4">
        <%= text_field_tag(:name, @company.name, :class => 'form-control') %>
     </div>
  </div>

  <div class="form-group">
     <%= label_tag(:category, 'Category:', :class => 'control-label col-sm-2') %>
     <div class = 'col-sm-4'>
        <%= collection_select(nil, :category_id, Category.all, :id, :description, :include_blank => 'select') %>
     </div>
  </div>

  <div class="form-group">
    <%= label_tag(:x, '', :class => 'col-sm-2') %>
    <div class='col-sm-2'>
        <button type="submit" class="btn btn-primary">one</button>
    </div>
  </div>

  <div class="form-group">
     <button type="submit" class="btn btn-primary col-sm-offset-2">two</button>
  </div>
</form>

最佳答案

第 1 步:围绕按钮构建一个 DIV。
步骤 2:为该 DIV 指定“col-sm-2 col-sm-offset-2”类。
第 3 步:将您的 BUTTON 放入该 DIV
第 4 步:如果这解决了您的问题,请给我反馈。

<div class="form-group">
  <div class="col-sm-2 col-sm-offset-2">
   <button type="submit" class="btn btn-primary">two</button>
  </div>
</div>

关于css - Bootstrap col-sm-offset-2 未对齐表单中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29066793/

相关文章:

javascript - 如何在选择框中隐藏下拉列表?

mysql - 是否有可能在 Rails 中从 MySQL 关闭中解救出来?

html - 如何在文本字段中显示提交按钮

twitter-bootstrap - 更大的 YouTube 电影 Bootstrap 模式

html - Bootstrap 3 - 如何在折叠的导航栏中正确显示按钮 (btn-navbar)?

javascript - 单击菜单在 <div> 中打开 pdf

javascript - ajax放置请求不接受参数中的id

ruby-on-rails - Capistrano 部署配置

javascript - 如何使用 Bootstrap 3 DateTimePicker 获取事件源

HTML 文件在不同的服务器中表现不同