Reputation: 41
So I have a bit of a problem here that has been hanging us up for days now. We can't seem to get the profile icon to stay on the top right when clicking on the expand collapse icon. As you can see in the pictures I linked screenshot 1 is how we want it to appear at all times. Stationed on the right of collapse and not having it drop down as it appears in screenshot 2. We tried searching various threads and tried what was described to no avail. Pull-right, float-right, navbar-right. Nothing seems to work and it is always dragged down when clicking the expand icon. Does anyone have any insight as to what would need to be added to fix this problem? I'll include the code as well for you to take a look at.
Update, here is my Codepen It doesn't look pretty because of all the ruby links being removed though the error is still present with the profile picture dropping down when extending the collapse mode.
<nav class="navbar navbar-expand-md mb-0 pt-0 pb-0 pl-1 navbar-fixed-top
navbar-light bg-light">
<div class="container-fluid" >
<div class="row" style="width: 100%">
<div id="brand_wrapper" class="navbar-left" style="height: 50px">
<%= link_to "NAVBAR", root_path, class: "navbar-brand navbar-left", id: "brand" %>
</div>
<!-- Begin - Page links of about and blog wrapper -->
<div id="navbar_page_links_wrapper" style="height: 57px;">
<div class="blog navbar-nav my-4 ba_height">
<a class="nav-item nav-link pl-2 mr-2 theme_color navbar_item_link" href="#">
Blog
</a>
</div>
<div class="about navbar-nav my-4 ba_height">
<a class="nav-item nav-link mx-2 ml-0 theme_color navbar_item_link" href="#">
About
</a>
</div>
</div> <!-- End - Page links of about and blog wrapper -->
<!-- Start - Search bar and button -->
<div class="input-group d-lg-block d-md-none navbar-left navbar_search_bar ml-3 mr-1 ms_sbb" style="height: 50px; width: 215px;"> <!-- Begin - Navbar's Search -->
<input id="search_bar" class="form-control my-4" type="text" placeholder="Search for ... " aria-label="Search for ... ">
<span class="input-group-btn my-4 ms_sbb">
<!-- Clicking on the "City" button brings you to All Cities.
PROGRAMMERS NOTE: Currently, search is not working yet. -->
<%= link_to "City", cities_path, id: "city_btn", class: "text-white btn btn-info my-4", type: "button" %>
</span>
</div> <!-- End - Search bar and button -->
<% if user_signed_in? %> <!-- Begin - If Statement showing Profile Link if loggedin, otherwise two log buttons -->
<button class="navbar-toggler tog_btn" data-toggle="collapse" data-target="#navbarNav"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse pl-0" id="navbarNav">
<ul class="navbar-nav navbar-left">
<li class="nav-item">
<%= link_to "Link 1", city_url(current_user.city.friendly_id), id: "cs_ms", class: "ml-3 pr-3 nav-link mx-2 theme_color navbar_item_link right_border_link" %>
</li>
<li class="nav-item">
<a class="nav-link mx-2 theme_color navbar_item_link right_border_link pr-3" style="margin-left: 2px !important;" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link mx-2 theme_color navbar_item_link pr-3" style="margin-left: 2px !important;" href="#">Link 3</a>
</li>
</ul>
</div>
<div class="col"></div>
<div id="dropdown_logged_in" class="dropdown show navbar-right">
<a class="dropdown-toggle mt-3" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<%= image_tag current_user.avatar.navbar_pic, id: "nav_facebook_avatar", class: "dropdown-toggle" %>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
<h6 class="dropdown-header center p-1"> <%= link_to "#{current_user.first_name.capitalize}'s Profile", current_user, style: 'width: auto !important; font-size: 16px;', class: 'dropdown-item p-1 center' %> </h6>
<div class="dropdown-divider"></div>
<%= link_to 'Update', edit_user_registration_path, style: 'font-size: 16px; color: #C361F1;', class: 'dropdown-item p-0 center' %>
<hr style="margin-top:3px !important; margin-bottom:3px !important;">
<%= link_to "Logout", destroy_user_session_path, method: :delete, style: 'font-size: 16px; color: #C361F1;', class: 'dropdown-item p-0 center' %>
</div>
</div>
<% else %> <!-- Else statement displaying Login & Signup buttons since User is not signed in -->
<div class="col navbar-right pl-0">
<div class= "navbar-right pull-right float-right mt-4">
<%= link_to "<i class='fa fa-user mr-2'></i>Login / Signup".html_safe, new_user_session_path, id: "login-su-btn", class: "btn btn-primary" %>
</div>
</div>
<% end %> <!-- End - If Statement for displaying Logged status -->
</div>
</div>
Upvotes: 1
Views: 2217
Reputation: 2809
Your css requires many changes. Most of your issues are related to using a lot of unnecessary html elements with uneven number of columns. When the dropdown menu shows up, it spans an additional space and goes to the next line. A short way to fix your issue is to set your drop-down menu's position to absolute. You can add the below css (updated CodePen). I followed the same media width you specify in your application.
@media (max-width: 768px){
#navbarNav{
position: absolute;
top: 70px;
}
}
However, I would recommend doing a lot of css changes. You can use very simple css rules as you are using Bootstrap 4. You can get rid of row, while keeping the content. Remove unnecessary empty elements such as
<div class="col"></div>
and
<div id="brand_wrapper" class="navbar-left" style="height: 50px">,
unless you are using them in your full app. In such a case, you should render them as ul li elements as in Bootstrap 4.
Edit
In order to update the background of the dropdown menu, you may try the following. The color green is only for testing. Here is an updated CodePen.
@media (max-width: 768px){
#navbarNav{
position: absolute;
top: 70px;
}
.navbar-nav.navbar-left{
background-color: green;
}
}
Upvotes: 1