Design and placement of drop-down menus

Is it possible to adjust the hover effects to cover the full width of the dropdown menu and change the text color when hovering over the li element instead of the a element?

The desired effect is a black dropdown menu where, upon hovering over each link, the background of the li should change to rgba(255,255,255, 0.1) and the text color should change to rgba(102,245,66, 0.8). The li and a elements should not extend beyond the normal dropdown section.

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #1c1c1c;
  min-width: 240px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  padding: 12px 16px;
  z-index: 1;
  height: 300px;
  position: absolute;
  right: 0;
  top: 100;
}

ul {
  list-style: none;
  overflow: hidden;
}

li {
  font-size: 1em;
  text-align: center;
  padding-top: .5em;
  height: 75px;
  width: 240px;
  overflow: hidden;
}

a {
  color: #fff;
  text-decoration: none;
  font-size: 2rem;
  font-family: $main-font;
  width: 240px;
}

a:hover {
  color: rgba(102, 245, 66, 0.8);
}

li:hover {
  background: rgba(255, 255, 255, .2);
  color: #8FC3A1;
  width: 240px;
  cursor: pointer;
}

.dropdown:hover .dropdown-content {
  display: block;
}
<div class="dropdown">
  <span><i class="fa fa-bars">Just hover on it</i></span>
  <div class="dropdown-content">
    <ul>
      <li><a href="#home">Home</a></li>
      <li><a href="#about">About</a></li>
      <li><a href="#lin">Line Up</a></li>
      <li><a href="#contact">Contact</a></li>
    </ul>
  </div>
</div>

Answer №1

I believe the solution you are seeking pertains to changing the color of the a element when hovering over the li element.

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #1c1c1c;
  min-width: 240px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  padding: 0;
  z-index: 1;
  height: 300px;
  position: absolute;
  right: 0;
      left: 0;
}

ul {
  list-style: none;
  overflow: hidden;
  margin: 0;
    padding: 0;
}

li {
    font-size: 1em;
    text-align: center;
    margin-bottom: 10px;
}

li:hover {
  background: rgba(255,255,255, 0.1);
  color: #8FC3A1;
  cursor: pointer;
}
li:hover a{
  color: rgba(102,245,66, 0.8)
}


a {
  color: #fff;
  text-decoration: none;
  font-size: 2rem;
  font-family: $main-font;
  width: 240px;
}
.dropdown:hover .dropdown-content {
  display: block;
}
<div class="dropdown">
  <span><i class="fa fa-bars">fa-bar dropdown</i></span>
  <div class="dropdown-content">
    <ul>
      <li><a href="#home">Home</a></li>
      <li><a href="#about">About</a></li>
      <li><a href="#lin">Line Up</a></li>
      <li><a href="#contact">Contact</a></li>
    </ul>
  </div>
</div>

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

Expanding size on hover without affecting the alignment of surrounding elements

Imagine there are 10 divs on the page styled as squares, collectively known as the home page. Among these 10: 3 divs belong to the .event1 class, 5 divs belong to the .event2 class, and 2 divs belong to the .event3 class. <div class="boxes event1"> ...

Unable to view numbers on iPhone or ios device

I am facing an issue with displaying a phone number in the contact section on my website. The number shows up on desktop but not on my iPhone, even when I resize the screen to be smaller than my phone's display size. This issue has been tested on both ...

Integrate a scaling feature into an HTML webpage

I am having trouble with the columns in my div not being equal widths. Does anyone have any suggestions on how to fix this issue? Does anyone know of a better way to create a scale using div elements instead of tables? <DIV class="scale"> <D ...

Including emoticons in text without impacting the 'line-height'

Is there a way to add an emoticon within a paragraph without altering the line-height, regardless of the size of the emoticon? For example: I've tried using position: absolute or vertical-align: text-top, but neither seems to work. p img { hei ...

What is the best way to arrange data within the <th> tag to mimic a row layout?

Is there a way to align text within <th> tags of a table so that it appears in a row-like fashion, rather than up and down? I want the headings to be level with each other. For example, titles like Americas Center, Asheville, ..., Coopersville shoul ...

Mandate that users select from the available place autocomplete suggestions exclusively

I have integrated the "Places" Google API to enable address autocomplete in an input field on my website. However, since the service is limited to a specific area, I have implemented an autocomplete filter. The issue I'm facing is that users are stil ...

Please tap to dial: Access to navigation is restricted

Trying to add a click-to-call link with the following code: <a href="tel:+4912345678912">Tel: +4912345678912</a> Despite Google developers saying it should work, major mobile browsers are blocking the navigation when clicking on the link. It ...

The styling of Div remains unchanged by CSS

Currently, I am working on a website using HTML and CSS. I have created a division element and applied a class to it called profile_pic. However, when I make changes to this class in the CSS file, it does not reflect on the div. It seems like the styling ...

Is there a way to submit a form without navigating away from the current webpage?

I'm working on a registration form and I need help figuring out how to send the input information to the action.php file without the user being redirected to it. Is there a way to have the form submitted in the background and then redirect the user ba ...

Extension for Chrome - view source of current webpage

I'm attempting to develop my chrome extension to extract the current page source and identify the current URL, as seen in this example. If I were to visit https://www.google.com and the page source contains google I want my extension to display a ...

Ways to create a div that automatically increases in height to fit its text when the browser size decreases

In the following code snippet, there is a top bar with a lengthy text: <div class="topbar"> <div style="float:left;height:36px;line-height:36px;text-transform: none;"> long text.... </div> </div> Within the topbar ...

The location of the footer is not aligned correctly

Recently, I encountered an issue that has left me puzzled. The problem is that the footer on my webpage is appearing between the calendar button and the calendar itself. Here is a snippet from my calendar.html file: {% extends 'base.html' %} {% ...

Issues with displaying video content and controlling the Bootstrap 5 video carousel

I have encountered an issue while coding a website for a friend's company. He requested a video carousel to be added to his existing site, so I incorporated links and scripts for Bootstrap in order to create a gallery for his products and a carousel t ...

The function is not recognized while executing .mb_YTPlayer();

I'm currently working on creating a webpage with a video background using jquery.mb.YTPlayer, but I'm encountering an issue. I'm seeing an error message that says "Uncaught TypeError: undefined is not a function". Here is the code I a ...

What is the best way to retrieve the root binding node from a viewmodel in order to apply jQuery.blockUI when performing an AJAX post request?

Within my code, I have a designated DIV element that serves as the root node for applying knockout bindings like so: ko.applyBindings(viewModel, document.getElementById('myContainerDiv')); In all of my viewmodel types, there is a generic post m ...

Obtaining the scene's coordinates in Three.js

Struggling with a coding issue, I've scanned various discussions that don't quite address my specific problem. Any assistance would be greatly appreciated. In my HTML document, I am using the three.js library to create a scene titled scaledScene ...

"Styling with CSS and HTML: The Art of Rotating

<!DOCTYPE html> <html> <head> <style> .screencontainer{ margin: 0 auto; display: block; xxheight: auto; xxmax-width: 90%; align-items: middle; } .foundations-wrapper{ display: inline-block; background-color: yellow; padding: 10px; ...

Despite adding a content security policy within the meta tag of my HTML, the policy does not seem to be properly enforced

I have implemented the Content Security Policy within the HTML meta tag <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initia ...

Troubleshooting the Height Problem in Material-UI's Menu

I am trying to make the menu height responsive by setting it equal to the window height using CSS. I want the menu height to increase as the page length increases due to added elements. I have attempted using "height:100%" and "height: 100vh" in the styles ...

Exploring Java Selenium Capabilities

<div id="my_menu" class="sdmenu" style="float: right"> <div class="collapsed"> <span>Research and Retrieval System</span> Is there a way to select Research and Retrieval System using Selenium? ...