I have my navbar items in the order of "offerings," "about," and "contact us."
On the live website it is "about" then "contact us" then "offering"
Is there some sort of code or div grouping I can use to make sure they display in the order listed?
Pasting the code from my application.html.erb:
div class="navbar-order">
<ul class="nav navbar-nav navbar-right">
<div class="dropdown">
<button class="dropbtn"><li><%= link_to "Offerings", offerings_path %></li></button>
<div class="dropdown-content">
<li><%= link_to "Public Speaking", pages_public_speaking_path %></li>
<li><%= link_to "Nonverbal Communication", nonverbal_path %></li>
<li><%= link_to "Group Dynamics", group_dynamics_path %></li>
<li><%= link_to "Intercultural Communication", intercultural_communication_path %></li>
<li><%= link_to "Editing", editing_path %></li>
<li><%= link_to "Interviewing", interviewing_path %></li>
<li><%= link_to "Business Etiquette", business_etiquette_path %></li>
<li><%= link_to "Business Writing", business_writing_path %></li>
</div>
</div>
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Contact Form", new_contact_path %></li>
</ul>
</div>
ul {
display:flex;
list-style-type: none;
}
ul li {
margin-right:20px;
}
<nav>
<ul>
<li>The</li>
<li> Correct</li>
<li>Order</li>
</ul>
</nav>
Try to re-structure Your HTML nav markup.
The point is that You should put <li>'s in the <ul> and not the divs. If You create the markup properly and put some
display:flex or display:inline-block on the <ul>, there is no way that it's displayed in the broken order
Related
When I added the logo using navbar-brand to my header page, it overlaps the divs on various pages rather than being encapsulated by the header, as seen in the picture attached:
header overlapping divs
Does anyone know how to make sure the logo is in the same div as the rest of the header?
Here is my code:
<header>
<nav class="navbar bg-transparent navbar-fixed-top py-5">
<div class="navbar-inner">
<div class="container">
<nav class= "py-5">
<% if logged_in? %>
<div class="col-sm-2">
<%= link_to image_tag("logo1.png", size: "150x100", alt: "logo"), explore_path, class: 'nav navbar-brand navbar-left', id: 'logo-image' %>
</div>
<ul class="nav navbar-nav navbar-right">
<% #mentee = Mentee.find_by(user_id: current_user.id) %>
<% #mentor = Mentor.find_by(user_id: current_user.id) %>
<% if #mentee.nil? && #mentor.nil?%>
<li><%= link_to "Log out", logout_path, method: :delete %></li>
<% elsif current_user.mentee? %>
<li><%= link_to "Profile", menteeprofile_path(#mentee), method: :get %></li>
<li><%= link_to "Matches", matches_path, method: :get %></li>
<li><%= link_to "Log out", logout_path, method: :delete %></li>
<% elsif current_user.mentor? %>
<li><%= link_to "Profile", mentorprofile_path(#mentor), method: :get %></li>
<li><%= link_to "Matches", matches_path, method: :get %></li>
<li><%= link_to "Log out", logout_path, method: :delete %></li>
<% else %>
<li><%= link_to "Profile", userprofile_path(current_user), method: :get %></li>
<li><%= link_to "Matches", matches_path, method: :get %></li>
<li><%= link_to "Profile", profile_path, method: :get %></li>
<li><%= link_to "Log out", logout_path, method: :delete %></li>
</ul>
<% end %>
<% else %>
<%= link_to image_tag("logo1.png", size: "150x100", alt: "logo"), "/", id: 'logo-image'%>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Log in", login_path %></li>
<li><%= link_to "Sign up", "/users/new" %></li>
</ul>
<% end %>
</nav>
</div>
</div>
</div>
</nav>
</header>
header {
position: relative;
width: 100%;//footer = 100, topmenu = 50
max-width: 100%;
min-height: auto;
text-align: center;
color: #fff;
padding-bottom: 65px;
}
Here are two button tabs :
How to express
1:
<% if logged_in? %> then hide b button tag
2:
<% if studentlogged_in? %> then hide A button tag
both methods<% if logged_in? %> , <% if studentlogged_in? %> are valid
<% if logged_in? %> <<==#A button tab
<li><%= link_to "Users", users_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Tutor Center", login_path %></li>
<% end %>
<% if studentlogged_in? %> <<==#B button tab
<li><%= link_to "StudentUsers", student_users_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", studentcurrent_user %></li>
<li>
<%= link_to "Settings", edit_user_path(studentcurrent_user) %>
</li>
<li class="divider"></li>
<li>
<%= link_to "Log out", studentlogout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Student Center", studentlogin_path %></li>
<% end %>
Maybe you mean this structure:
<% if studentlogged_in? %>
...
<% elsif logged_in? %>
...
<% end %>
Where that shows the student one, the regular one, or nothing, but never both.
I think this is what you want:
<% if logged_in %>
# render partial containing html code for button A
<% elsif studentlogged_in %>
# render partial containing html code for button B
<% else %>
# render both partials
<% end %>
I'm trying to create a navbar with two links generated in Ruby on Rails. For now, pretty much trying to make the brand on the left and either log in/sign up or log out/post ad on the right. However, my right nav bar is falling below on a new line. Like the width of the navbar isn't large enough to hold all the items.
Here is a screenshot of what I am describing....
The right navbar is falling below the brand.
index.html.erb
<nav class="navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">SHIP LIST</a>
</div>
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in?%>
<li><%= link_to 'post ad', new_listing_path %></li>
<li><a href="#"><%= link_to 'log out', destroy_user_session_path, :method => :delete %></li>
<% else %>
<li><a href="#"><%= link_to 'sign up', new_user_registration_path %></li>
<li><a href="#"><%= link_to 'log in', new_user_session_path %></li>
<% end %>
</ul>
</div>
My css is as follows, I did have to make changes with it so the alerts for Devise show below the navbar, so that may be causing it. I don't think it is but.
body {
font-size: 62.5%;
font-family: Helvetica, sans-serif;
}
.alert-box {
color:#555;
border-radius:10px;
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:11px;
padding:10px 10px 10px 36px;
margin:10px;
span {
font-weight:bold;
text-transform:uppercase;
}
}
.danger {
background:#ffecec url('images/error.png') no-repeat 10px 50%;
border:1px solid #f5aca6;
}
.success {
background:#e9ffd9 url('images/success.png') no-repeat 10px 50%;
border:1px solid #a6ca8a;
}
.warning {
background:#fff8c4 url('images/warning.png') no-repeat 10px 50%;
border:1px solid #f2c779;
}
.notice {
background:#e3f7fc url('images/notice.png') no-repeat 10px 50%;
border:1px solid #8ed9f6;
}
With the following code pertaining to the right nav bar...
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in?%>
<li><%= link_to 'post ad', new_listing_path %></li>
<li><a href="#"><%= link_to 'log out', destroy_user_session_path, :method => :delete %></li>
<% else %>
<li><a href="#"><%= link_to 'sign up', new_user_registration_path %></li>
<li><a href="#"><%= link_to 'log in', new_user_session_path %></li>
<% end %>
</ul>
Remove the link tags like so...
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in?%>
<li><%= link_to 'post ad', new_listing_path %></a></li>
<li><%= link_to 'log out', destroy_user_session_path, :method => :delete %></li>
<% else %>
<li><%= link_to 'sign up', new_user_registration_path %></li>
<li><%= link_to 'log in', new_user_session_path %></li>
<% end %>
</ul>
Rails will automatically generate them for you, so you don't need to add them in like that manually. It was overflowing as it was trying to add in four links instead of two. Nothing to do with the Devise gem, that is being generated in the body of the HTML page.
My navigation bar currently looks like this:
My code is below:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
Text Planner
</a>
</div>
<% if user_signed_in? %>
<p class="navbar-text navbar-left">Welcome, <strong><%= current_user.first_name.to_s+" "+current_user.last_name.to_s %></strong></p>
<div class="nav navbar-nav navbar-right">
<%= link_to "Home", home_path, :class => 'btn btn-default navbar-button' %>
<div class="btn btn-default dropdown-toggle navbar-button" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Menu</div>
<ul class="dropdown-menu">
<li><%= link_to "Search For Events", root_path %></li>
<li><%= link_to "My Bookmarks", user_bookmarks_path(current_user.id)%></li>
<li><%= link_to "My Upcoming Reminders", user_reminders_path(current_user.id)%></li>
<li><%= link_to "My Profile", user_path(current_user.id)%></li>
<li role="separator" class="divider"></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
</ul>
</div>
<% else %>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", home_path, :class => 'navbar-text' %></li>
<li><%= link_to "Sign up", new_user_registration_path, :class => 'navbar-text' %></li>
<li><%= link_to "Login", new_user_session_path, :class => 'navbar-text' %></li>
</ul>
<% end %>
</div>
</nav>
How do I move the home and menu buttons to the left and center them vertically? Also, I would like to keep them clickable buttons while removing the outline of a button with the white background so they match the left side of my navigation bar. Thanks in advance.
It's very simple, actually, set your line-height and div height to the same (here's a quick example):
#navbar a{
width: 200px;
height: 40px;
display:inline-block;
color:white;
line-height:40px;
}
This is provided your buttons are formed using CSS, but I believe it works for other elements, as well.
I am using bootstrap for creating twitter like app. The contents on the nav bar, under "nav pull-right" disappears when the window size resized to small. How do i do that? Here is my erb file..
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<%= link_to "cntwitter", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right" id="right_nav">
<li><%= link_to "Home", root_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", users_path %></li>
<li id="fat-menu" class="dropdown">
Account <b class="caret"></b>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
The twitter bootstrap scaffolding, or grid, is static by default. It sounds like you want the contents of your web page to scale with the browser window. In that case, I would recommend using the "fluid" scaffolding :: http://twitter.github.com/bootstrap/scaffolding.html#fluidGridSystem