Creating a uniform hover effect for both an item and the link contained within it

I am currently working on creating a menu using an unordered list (ul) with a left float. Each list item (li) will contain a link, and when hovering over the li, the link should change to a transparent color. Additionally, each li has a unique ID and background image associated with it.

I have made progress on the menu, but there is a noticeable difference between the hover effect on the link and on the li. You can view my code here: http://jsfiddle.net/mhhbs/

Here is an example of what I mean by a hover image:

Below is the CSS code I have written so far:

#nav {
    font: 30px 'LeagueGothicRegular', Arial, sans-serif;
    color: #f9f8cc;
    width:450px;
    clear: both;
    height: 56px;
    margin: 0px 0px 0px 50px;
    background:#c2c2c2;
}

#nav ul {
    margin: 0;
    padding: 0;
}

#nav li {
    list-style-type: none;
    background-image: transparent;
    color: #FDE99D;
    float: left;
    height:50px; width:100px;
    border-right:1px #900 solid;
    text-align:center;

}

#nav li a {
    /**padding:10px 20px 10px 16px;**/
    color: #000;
    text-shadow: 0px 2px 2px #222;
    text-transform: uppercase;
}

#nav li a:hover {
    color: #999;
    color:transparent !important;
    text-shadow: none;
}

#nav li:hover {
    background:url(http://cdn1.iconfinder.com/data/icons/duesseldorf/32/home.png) red; 
    background-size: 83px 56px; 
    color: #999;
    color:transparent !important;
    text-shadow: none;
}

Answer №1

Revise

#navigation li a:hover {

to be

#navigation li:hover a {

http://jsfiddle.net/abcd123/

By doing this, both styles will be triggered by hovering over the li element.

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

What is the best way to include default text in my HTML input text field?

Is it possible to include uneditable default text within an HTML input field? https://i.stack.imgur.com/eklro.png Below is the current snippet of my HTML code: <input type="text" class="form-control input-sm" name="guardian_officeno" placeholder="Off ...

If an element with a "hidden" display property is loaded in the browser window, will it be visible?

Is an element in a hidden display still using memory when the page is loaded? It's convenient to have many elements on a page, but if 99 elements are hidden and only 1 is displayed, does that impact the loading of the page? I'm curious if the pa ...

Styling your navigation with a CSS background

Having trouble creating a custom CSS navigation for my website. Below is the code snippet of my attempt at a vertical navigation: <style type="text/css"> /* Custom stylesheet */ #cssmenu > ul { list-style: none; margin: 0; padding: 0; vertical-a ...

The motion does not adhere to the delay in transition

How come the first animation doesn't have a delay when hovering in and out? It just disappears instantly. I'm attempting to achieve a delay similar to the hue-rotate effect when hovering in and out. https://jsfiddle.net/u7m1Ldq6/15/ <div id ...

Is it possible to alter CSS based on the width of the webpage using javascript

We are currently developing a web application that will be deployed on various devices such as mobile phones, iPads, iPhones, and Android. Instead of using user agents to show different views, I prefer having CSS that adjusts based on the screen width. We ...

Efficiently refine your search using the combination of checkboxes and dropdown menus simultaneously

I am currently in the process of creating a highly sortable and filterable image gallery that utilizes numerous tags. The inspiration for this project stems from a similar question on Stack Overflow regarding dropdown menus and checkboxes. You can view the ...

The evolving impact of the HTML5 <video> element

I've been attempting to find information on this topic, but unfortunately my search has not been very successful. I vaguely recall coming across a tutorial that covered something like this. Does anyone happen to know how to alter the perspective of a ...

Issue with functionality of inline list menu

Having trouble with a JQ drop down menu and suspect it's an HTML/CSS issue. Spent hours tweaking it, but still not working as expected. Looking to understand the correct approach rather than just getting it to function. The slidetoggle feature is mess ...

Issues with proper layout of HTML table

I am currently working on creating a table to showcase inmate information. Utilizing Flask and Jinja, I am transferring data from my Python file to the HTML file: headings = ("First", "Last", "Court Date", "Bond Amount&q ...

Effortlessly Transition to Full Screen with Div Expansion on Click

I'm currently working on creating a smooth transition for a div to expand fullscreen when clicked. My goal is to achieve a similar effect as the case studies on this website: Although my code can make the div go fullscreen, there's an issue with ...

Commencing CSS Animation Post Full Page Loading

I am looking for a solution using WordPress. In my specific case, I want the CSS Animations to take effect only after the page has completely loaded. For example: click here This is my HTML: <div class="svg-one"> <svg xmlns="ht ...

Troubleshooting problem with CSS background image

I'm looking to make my webpage more dynamic and interactive. One issue I have is that the background image of the body element stretches when new elements are added, which is not the desired behavior. Any suggestions on how I can fix this? <styl ...

Centralized and standardized approach to invoking a function

Explaining this concept may be a bit challenging, but I'll give it a shot: Within the .boxes class div, there are looped elements with the class .box. Each .box element contains two child elements: one with the class .box-header and another with the ...

What steps should I take to ensure that the ajax request for the favorites button works effectively when clicked?

I've set up a list on my website with a favorites button for each item. The button is an image that users can click on. Here's the PHP code for it: echo "<img src=\"./images/emptystar.png\" alt=\"favorite\" class=\"fa ...

Mobile Device Centering Problem with Bootstrap Cards

Despite my thorough research efforts, I have been unable to find a solution. The code snippet below is meant to display the image provided, but it seems to shift to the left when viewed on a mobile device. If anyone can assist me with this issue, I would ...

Troubleshooting Date Format Problems with Jquery Datepicker

I am dealing with a situation where I have a birth date and need to automatically calculate the retirement date. Everything works smoothly unless the dateFormat is modified. When attempting to change the date format to 'dd/mm/yy', an issue arise ...

Assigning a background image based on the quantity of items in an array or object

I'm having trouble appending divs and setting their background image based on the number of items in an array or object. Despite adding the divs correctly, all of them end up with the same background image when only three should have it. Can someone e ...

Having trouble retrieving data from the fetch database. The login page seems to be stuck in a continuous loop and won't let me

Every time I attempt to log in through: webhost/adminlogin.php, I am redirected back to the same page. Did I forget to add something? Thank you for your assistance. Here is my script: This is what is included in my adminlogin.php file: <?php session ...

Ensuring Proper Highlighting for HTML Select Options

I am working on a project involving an HTML Drop-down menu. Check out the code I have so far: http://jsfiddle.net/dineshk/u47xjqLv/ HTML Code <select> <option class="first" style="display:none;">HH</option> <option class= ...

Struggling to click on a link while viewing the site on your mobile device?

Recently dove into the world of implementing mobile responsive design for a website I've been working on. While conducting some testing, I observed that the main tabs which direct users to different sections of the site, normally easy to click on desk ...