Anchor elements appear to overlap when in hover state

I am experiencing a challenge with creating a dropdown for the navigation menu on my mobile view. The anchors are overlapping and my attempt to stack them on top of each other using display block and margin-bottom has not been successful as evidenced by the issue persisting.

html

  <div id="brand">
    <h1>brand</h1>
    <nav>
      <div class="fa fa-plus"></div>
      <div class="fa fa-cog">
        <a href="#">Edit Profile</a>
        <a href="#">Dashboard</a>
      </div>
      <div class="fa fa-sign-out"></div>
      <input type="search" id="main-q" name="q" placeholder="Search" data-value="" value="">
    </nav>
  </div>

css

nav .fa a {
  display: none;
}

nav .fa:hover a {
  display: block;
  position: absolute;
  top: 75px;
  color: black;
  margin-bottom: 1em;
}

#brand {
  border-bottom: 1px solid #B2B2B2;
  background: white;
  color: darkgrey;
  padding: 1em;
}

#brand h1 {
  margin-bottom: .5em;
  float: left;
}

View the demonstration on jsfiddle

What could be a potential solution to this issue?

Answer №1

Everything is going smoothly now. The key issue was ensuring that the position: absolute was set for a. Simply encapsulate those anchor elements a within UL li and then adjust the position for UL.

CSS:

nav .fa .child { /*updated CSS*/
  display: none;
  border:1px solid red;
  }

nav .fa:hover .child { /*updated CSS*/
  display: block;
  position: absolute;
  top: 75px;
  color: black;
  margin-bottom: 1em;
}

HTML

<div class="fa fa-cog">
    <ul class="child"> <!--class child for dropdown-->
        <li><a href="#">Edit Profile</a></li>
        <li><a href="#">Dashboard</a></li>
    </ul>
</div>

Check out the updated version on JSFIDDLE

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

Tips for effectively utilizing tabs to showcase information for a particular user rather than solely the initial one

I am fetching multiple user data from an API call, and all users are rendered using the same HTML and CSS. However, when I switch between tabs for each user, only the first user's information changes instead of the specific user I clicked on. I have a ...

Sending JSON Data over URL

I am facing a challenge with passing data between two HTML files. My initial solution involved sending the data through the URL using the hash and then parsing the link using JSON.parse(window.location.hash.slice(1));. This method worked for a few attempts ...

A comprehensive guide on adjusting the height of images dynamically using only CSS

Calling all CSS experts: I'm curious if it's doable to replicate the image scaling effect seen on this website using only CSS? Please note that the images only begin scaling when the height of the browser window changes, not its width. (I menti ...

Trimming Picture on User's Device

Currently, I am utilizing the jQuery ImgAreaSelect 0.9.10 plugin to crop images that are uploaded by users. The data input format being used is "multipart/form-data". Upon cropping an image with the plugin, it provides me with coordinates in pixels. Howev ...

JavaScript not functioning on Express-powered HTML document

I have set up an express server to render my payj.html file, which includes a script tag for the clyint.js file. However, I am encountering an error in the browser's console: GET net::ERR_ABORTED 404 I also attempted to include all the JavaScript ...

Media queries for the header background image display

I am currently working on a small web project and I want to change the background image in the header section while also making it responsive. I attempted to use a class called "header_accueil" in my header to distinguish different sections of the site, bu ...

Center the text within the div and have it expand outwards from the middle if there is an abundance of text

I have a div that is in the shape of a square box and I want it to be centered. No matter how much text is inside, I would like it to remain in the middle. I am using JQuery to create my square box and would like to center it using CSS. Here is my code: &l ...

Arranging elements with z-index does not necessarily bring dropdown HTML content to the front

Can someone help me with creating a dropdown menu that expands on top? I have tried using the z-index property, but for some reason it seems to blend in with the rest of the site. The issue occurs when entering "Enter your region" on my website 33hotels.co ...

Responsive Button Sizing with Bootstrap 4

Would it be possible to use Bootstrap 4 to automatically apply the 'btn-sm' class (small button) when the media breakpoint is xs? I want the buttons to remain their default size unless the screen size is xs, where they should switch to btn-sm au ...

Is there a way to create a flexbox that combines a centered fixed child with a fixed child at the bottom?

I'm trying to create a layout using flexbox that looks like this: | | | | | CENTER FIXED ELEMENT | | | | BOTTOM FIXED ELEMENT | Here is the flexbox CSS I've attempted: .wrapper{ ...

Personalize the font style of the icon property in Material UI Table when utilizing text in place of an icon

In my React app using Material UI table, I needed a custom event on the action button that displayed text instead of the usual icons for Add, Update, or Delete. Instead of creating my own icon, I opted to use text for the button like so... <MaterialTabl ...

Various JSON Tag values occurring more than once

Upon receiving a JSON Object in HTML, I am passing it to a JavaScript function defined below. The issue arises when the same folderName appears repeatedly on the HTML page. JSON Object: { "folderName": "arjunram-test", "objects": [ { ...

Divs are stubbornly resisting the urge to behave like block elements

.useless { float: right; clear: right; border: 1px dashed blue; height: 50px; width: 100%; } div.pretraga { border: 3px groove red; width: 20%; float: right; margin-right: 5%; border-top: 0; display: flex; justify-content: center; height: 250px; <div cl ...

Adjust the appearance of a glyphicon by modifying its color according to various criteria

Using angularjs, I implemented ng-repeat to display details in a table. In the final column, I aim to display the glyphicon 'glyphicon glyphicon-stop' in a specific color. <tr ng-repeat="ps in $ctrl.personLst"> <td>{{ ps.id}}</td& ...

Issue with click event for submit button in ASP.Net following a change in dropdown list index using JavaScript

Currently, I have an asp.net application where a confirmation popup alert is displayed when the selected index changes to a specific value ("Cancelled") in a dropdown list. <asp:DropDownList ID="ddlStatus" runat="server" CssClass="selectstyle" DataText ...

Eliminate any hyperlink mentions from the Media Print Screen

I'm experiencing a small issue where I am unable to remove the link reference from the print view. Below is the HTML code snippet: <table style="width: 436px; height: 374px;" border="0" cellpadding="5"> <tbody> <tr style=" ...

I possess a certain input and am seeking a new and distinct output

I am looking to insert a word into an <input> and see an altered output. For example, Input = Michael Output = From Michael Jordan function modifyOutput() { var inputWord = document.getElementById("inputField").value; var outputText = "print ...

Exploring methods to modify the style attribute of a div tag in .NET

Using .NET, we need to access the CSS style of a div and input certain values in the code behind on page load. Since the div is located on the master page and this is another separate page, we are unable to add RUNAT="SERVER" to the div. ...

How to implement jquery select functionality on clickable table rows?

I've come across a challenge while trying to implement clickable table rows with the jquery selectable function. Everything works perfectly fine with li elements, but I seem to hit a roadblock when using tables - the click event just stops working. Wh ...

Tips for maintaining a fixed size for CSS grid cells' minimum and maximum dimensions

I am attempting to utilize CSS grid to create an entirely fixed layout. This layout is for an embedded application that contains both GUI elements and text fields. The sizes of the cells should remain unchanged and not readjust as their content grows or sh ...