How can I prevent the CSS dropdown menu from causing the navigation bar to stretch in height?

I'm currently working on integrating a CSS dropdown menu into my navigation bar that will only appear when a user hovers over the settings icon.

However, I've encountered an issue where hovering over the settings icon causes the dropdown menu to stretch the height of the navigation bar. My goal is to resolve this issue so that the dropdown menu does not affect the navigation bar's height in any way. So far, using z-index hasn't helped make the dropdown menu visually pop out either. Here are some visual examples:

Before Hover -

During Hover -

(The black line indicates the bottom of the navigation bar)

Any assistance would be greatly appreciated - thank you!!

application.html.erb

<ul class="navigation-bar">

  <div class="navigation-bar-right-inset">

    <li class="navigation-bar-right"> <span class="settings"> <a href="#"> <img class="#" src="/assets/settings.svg"> </a> </span>
      <ul class="dropdown">
        <li> <%= link_to "sign out", destroy_user_session_url, method: :delete %> </li>
        <li> <%= link_to "profile", edit_user_registration_path %> </li>
      </ul>
    </li>

  </div>

</ul>

CSS Stylesheet

.navigation-bar {
  width: 100%;
  top: 0;
  position: fixed;
  z-index: 1050;
  list-style-type: none;
  overflow: hidden;
  background-color: rgb(251,251,251); 
  border-bottom: 1px solid #FFF;
}

.navigation-bar-right-inset { margin-right: 9%; }

.navigation-bar-right { float: right; }

.navigation-bar-right .settings img { 
  height: 65px; 
  margin-top: -5px;
  opacity: 0.3;
}

.navigation-bar-right .settings img:hover { opacity: 0.5 }

ul li .dropdown {
  display: none;
  position: relative;
  width: auto;
}

ul li:hover .dropdown { display:block }

Answer №1

What do you think of this solution?

ul li .dropdown {
 display: none;
 position: absolute;
 width: auto;
 top: 50px; //adjust if necessary 
 right: 0; // adjust if necessary
}

I also eliminated overflow:hidden from .navigation-bar since it was causing the dropdown menu to be hidden.

Visit this link for a live example

Answer №2

Here is the suggested CSS code:

ul li .dropdown {
  display: none;
  position: fixed;
  z-index:100;
  width: auto;
  background-color: rgb(231,231,231);
}


.navigation-bar {
  width: 100%;
  top: 0;
  position: fixed;
  z-index: 90; //--- must be lower than ul li .dropdown 
  list-style-type: none;
  overflow: hidden;
  background-color: rgb(251,251,251); 
  border-bottom: 1px solid #FFF;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

style of placing a space between objects

Is there a way to create space between the border (underline hover effect) and have the color of the line be red? a { text-decoration: none } li { display: inline; } li:hover { text-decoration: underline; } <li><a href=""> abc < ...

$.ajax causing a JSON input string malfunction

My web API requires the following JSON format for input: [{ "atrSpaUserId": "47fe8af8-0435-401e-9ac2-1586c8d169fe", "atrSpaClassLegendId": "00D18EECC47E7DF44200011302", "atrSpaCityDistrictId": "144d0d78-c8eb-48a7-9afb-fceddd55622c"}, { "atrSpaUserId": "47 ...

Sluggishness in jQuery animated effects

Looking to add a fade animation with jQuery to a div's opacity but encountering a delay issue when using an if/else statement. Even setting the delay to '0' did not resolve the problem. Below is the code snippet: $(window).scroll(function() ...

The Swiper slider is unable to display several views at once in the slider layout

I recently started using the amazing swiper slider plugin available here My goal is to replicate the demo-no-210 from that repository. Here is the code snippet I am working with: index.html <!DOCTYPE html> <html> <head> <meta ...

Tips for maintaining consistent image dimensions while resizing your browser window

I'm having trouble preventing an image from resizing when I adjust the browser size. If you click on this link and try resizing your browser, you'll see what I mean - the image stays the same. I've attempted various methods but haven't ...

The sidebar appears to be hovering above the footer section

I am currently working on creating a sidebar that sometimes ends up being longer than the main content section. You can check out my demo here: http://jsfiddle.net/y9hp4evy/1/ and another case here: http://jsfiddle.net/y9hp4evy/2/ (If I add a height to th ...

Is it possible for a website to instruct a user's browser to save the entire page locally?

Is it possible for a (single-page) website to instruct a user's browser to save the entire page locally? To provide some background: I am running a website on a server that bills based on bandwidth usage. Since the content of the site remains mostly ...

I am looking for a way to batch upload several images from an HTML page to a nodejs server, where I can then rename and

Exploring the world of nodejs, I am seeking guidance on updating multiple images from HTML to node js. Specifically, how can I rename each image differently and save them to a directory? Alternatively, is there another solution that would better suit my ne ...

What is the best way to use jQuery to select a group of table rows based on the value of a

My current issue involves using a jQuery selector to move table rows "UP" and "Down." Here is the Table structure in HTML: jQuery Portion : $(".up,.down").click(function() { var row = $(this).parents("tr:first"); if ($(this).is(".up")) { ...

Creating a full-width tab card with Bootstrap-Vue: A step-by-step guide

I stumbled upon something similar in the documentation for bootstrap-vue: A card with tabs: https://i.sstatic.net/HoVEC.png Now, how can I style the tabs to look like this: https://i.sstatic.net/dbsRj.png This is my current code: <b-card no-body ...

Tips for including a new class in an HTML element

My goal is to add a specific class to an HTML tag, if that tag exists. This is the code I have attempted: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>index</title> <style> ...

The div just won't stay the size I want, no matter what

Here is a snippet of HTML code: <div class="pointwrap"> <div class="imgwrap"> <img src="howtoplay1.jpg" height="101" width="177"/> </div> <div class="textwrap"> Tap Anywhere in the Drop zone to release a ball. ...

Is it possible to maintain HTML, JS, and CSS files as separate entities when developing Vue.js components, similar to how it is

Is it possible to maintain separate HTML, JS, and CSS files while creating Vue.js components? I recently read the "Why Vue.js doesn't support templateURL" article which discusses this topic. "Proper modularization is a necessity if you want to bu ...

difficulties adding specific new events within a designated range of dates

I am currently utilizing the amazing jQuery plugin known as fullcalendar. Here is the issue that I have encountered. When a user selects a range of dates by clicking and dragging over 2 or 3 consecutive dates on the calendar. For instance, from the 3rd t ...

Troubleshoot: Difficulty with accessing nested tag name using getElementsByTagName

I'm currently working with a div that contains a table and its data pulled from a database. <div id="content"> <table> <tbody> <tr> <th class="header" colspan="2">Food items include:</th> </tr> ...

SPFx WebPart - Tabbed Interface

I am new to developing SPFX WebParts and currently working on creating a Tab WebPart. The HTML appears to be rendering correctly, but I'm facing issues with the Javascript functionality not firing as expected. Any assistance or guidance on how to prop ...

What is the method for implementing a "preset highlighting" notification in the Typeahead feature?

At the moment, I've noticed that in Typeahead, when a query doesn't return any results, no dropdown list or message is displayed to inform the user about the empty result. Is there a way to include a single result in the dropdown list that says ...

How can we transition a line of code from PHP to Smarty?

I'm currently working on converting a php line of code to Smarty. I've managed to convert the variable successfully, but I am struggling with incorporating the small syntax before it. Below are both sets of syntax - how can I include link_it with ...

Leveraging Bootstrap cards to create clickable links

I am working with a bootstrap card that serves as a link. When I attempt to enclose it with an <a>, the styling of the card gets completely altered. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min ...

Before displaying the output, Flask first shows the HTML heading

I have developed a user input form that displays a graph after selection. The title of the graph result is 'Results,' however, it appears before the user makes a selection. Check out the screenshot below: https://i.sstatic.net/1WkZ4.png No sele ...