0

我希望我的登录表单在一行中显示相邻的字段,而不是在彼此的下方。

标题:

更新:此代码现在可以使用

<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
  <%= link_to "Apollo", root_path, id: "logo" %>
  <nav>
    <ul class="nav pull-right">

<%= form_for(:session, url: sessions_path, :html => { :class => "form-inline"}) do |f| %>
  <input id="session_email" name="session[email]" type="text" class="input-medium" placeholder="Email">
  <input id="session_password" name="session[password]" type="password" class="input-medium" placeholder="Password">
  <button type="submit" class="btn btn-small btn-primary">Sign in</button>
<% end %>

</ul>
  </nav>
</div>
</div>
</header>

生成的 HTML

<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
  <a href="/" id="logo">Apollo</a>
  <nav>
    <ul class="nav pull-right">

          <div class="row">
            <div class="span2 offset3">
              <form accept-charset="UTF-8" action="/sessions" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="xmS0FBX+pX8ZzBr/yHIUNmXOQMFI4krsv3FxIl51Hjg=" /></div>

                  <input id="session_email" name="session[email]" placeholder="Email" size="30" type="text" />

                  <input id="session_password" name="session[password]" placeholder="Password" size="30" type="password" />

                  <input class="btn btn-small btn-primary" name="commit" type="submit" value="Sign in" />

</form>                </div>
          </div>
    </ul>
  </nav>
</div>
</div>
</header>

自定义 CSS.SCSS

@import "bootstrap";

/* mixins, variables, etc. */

$grayMediumLight: #eaeaea;

@mixin box_sizing {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

/* forms */

input, textarea, select, .uneditable-input {
  border: 1px solid #bbb;
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  @include box_sizing;
}

input {
  height: auto !important;
}
4

2 回答 2

3

更改您的 CSS。

视图没有问题。

看起来您正在使用引导程序,因此将类添加.form-inline到表单中:

<%= form_for(:session, url: sessions_path, :html => { :class => "form-inline"}) do |f| %>
于 2012-12-16T02:18:34.207 回答
2

表单中的每个input元素都应显示为内联或内联块,并且应调整大小以适合单行上的所有元素。任何溢出都会被撞到下一行。

给表格上课。例如,inline_form

form.inline_form input {
  display: inline-block;
  width: 80px; //small for example
}

使用您的代码的示例

于 2012-12-16T08:17:11.547 回答