Reputation: 3231
Im working on a "Mock" facebook clone and im trying to do a simple "log in" form in the navbar.
I have it working pretty decent so far however the "Log in" submit button is floating much higher than the other items:
So it's looking ok but Im guessing the button is going where the "labels" normally go.
Here is my code thus far:
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<%= form_for(resource, as: resource_name, url: session_path(resource_name), class: "form-inline") do |f| %>
<div class="field field form-group mb-2">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control" %>
</div>
</li>
<li class="nav-item">
<div class="field field form-group mx-sm-3 mb-2">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "current-password", class: "form-control" %>
</div>
</li>
<li class="nav-item">
<div class="actions mb-2">
<%= f.submit "Log in", class: "btn btn-primary" %>
</div>
</li>
<% end %>
</ul>
</div>
It was kind of frustrating to wrap everything in an li
and the whole group in a ul
I can't tell if that's 100% necessary...but it's the only thing that would work.
I suppose I could adjust the margin-top
by some % but im sure there is a cleaner obvious way Im missing.
Upvotes: 0
Views: 1913
Reputation: 3505
This should work, you should not be wrapping your form inside a li tag and then ending it outside that li, try this, just change this code to your erb tags, running this with regular html for displaying it
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<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" id="navbarSupportedContent">
<div class="navbar-nav ml-auto">
<form class="form-inline">
<div class="field field form-group mb-2">
<label for="email">Email</label><br />
<input type="email" class="form-control" %>
</div>
<div class="field field form-group mx-sm-3 mb-2">
<label for="password">Password</label><br /><br />
<input type="password" class="form-control" %>
</div>
<div class="actions form-group mb-2">
<input type="submit" class="btn btn-primary" %>
</div>
</form>
</div>
</div>
</nav>
</body>
</html>
Upvotes: 1