Bootstrap 5 在导航栏中对齐项目
Bootstrap 5 Aligning Items In Navbar
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<%= link_to "My Ozone", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<%= form_tag zipcode_path, :method => 'POST' do %>
<div class="form-inline my-2 my-lg-0">
<%= text_field_tag 'zipcode', nil, placeholder: "Search Zipcode", class: "form-control mr-sm-2" %>
<%= submit_tag 'Search', class: 'btn btn-outline-secondary my-2 my-sm-0' %>
</div>
<% end %>
</div>
</nav>
我已经在 Rails 项目上完成了一个 Ruby,该项目根据搜索的邮政编码显示臭氧信息。但是,我似乎无法获得彼此相邻的字段和提交按钮。我尝试了各种不同的方法,例如更改 div class 并将内容包装在表单标记中,但似乎无法解决问题。寻求有关使项目在同一行对齐的帮助。
您需要在 Bootstrap 中使用 d-flex
而不是 form-inline
class 5.
Dropped form-specific layout classes for our grid system in Bootstrap 5. Use our grid
and utilities instead of .form-group
, .form-row
, or .form-inline
- more details here
您的代码应如下所示:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<%= link_to "My Ozone", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<%= form_tag zipcode_path, :method => 'POST' do %>
<div class="d-flex my-2 my-lg-0">
<%= text_field_tag 'zipcode', nil, placeholder: "Search Zipcode", class: "form-control mr-sm-2" %>
<%= submit_tag 'Search', class: 'btn btn-outline-secondary my-2 my-sm-0' %>
</div>
<% end %>
</div>
</nav>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<%= link_to "My Ozone", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<%= form_tag zipcode_path, :method => 'POST' do %>
<div class="form-inline my-2 my-lg-0">
<%= text_field_tag 'zipcode', nil, placeholder: "Search Zipcode", class: "form-control mr-sm-2" %>
<%= submit_tag 'Search', class: 'btn btn-outline-secondary my-2 my-sm-0' %>
</div>
<% end %>
</div>
</nav>
我已经在 Rails 项目上完成了一个 Ruby,该项目根据搜索的邮政编码显示臭氧信息。但是,我似乎无法获得彼此相邻的字段和提交按钮。我尝试了各种不同的方法,例如更改 div class 并将内容包装在表单标记中,但似乎无法解决问题。寻求有关使项目在同一行对齐的帮助。
您需要在 Bootstrap 中使用 d-flex
而不是 form-inline
class 5.
Dropped form-specific layout classes for our grid system in Bootstrap 5. Use our grid and utilities instead of
.form-group
,.form-row
, or.form-inline
- more details here
您的代码应如下所示:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<%= link_to "My Ozone", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<%= form_tag zipcode_path, :method => 'POST' do %>
<div class="d-flex my-2 my-lg-0">
<%= text_field_tag 'zipcode', nil, placeholder: "Search Zipcode", class: "form-control mr-sm-2" %>
<%= submit_tag 'Search', class: 'btn btn-outline-secondary my-2 my-sm-0' %>
</div>
<% end %>
</div>
</nav>