Change the color of the parent navigation when in a submenu

Check out the jsFiddle link here : http://jsfiddle.net/wQs5a/

I'm working on changing the color of the parent item to gray (#aaaaaa) when it's highlighted, and similarly highlighting the submenu item in the same gray color (which is currently working fine).

However, I want the parent item to return to green (#60a74a) when hovering over the submenu item.

Any assistance would be much appreciated. Based on my research, it seems like I might need some Javascript.

Thank you for your help!

CSS Code:

.leftNav {
height:58px; 
background: #1c1c1c; 
position:relative; 
font-family:'TradeGothic LT CondEighteen'; 
font-size:18px; 
width:88px; 
z-index:500;
}

.leftNav .table {
/*display:table;*/ 
margin:0 auto;
}

.leftNav .select,
.leftNav .current {
margin:0; 
padding:0; 
list-style:none; 
display:table-cell; 
white-space:nowrap;
}

.leftNav li {
margin:0; 
padding:0; 
height:auto; 
float:left;
}

.leftNav .select a {
display:block; 
height:58px; 
float:left; 
background: #1c1c1c; 
padding:0 20px 0 20px; 
text-decoration:none; 
line-height:58px; 
white-space:nowrap; 
color:white;
}


.leftNav .select a:hover, 
.leftNav .select li:hover a {
background: #aaaaaa; 
padding:0 0 0 0px; 
cursor:pointer; 
color:white;
}

.leftNav .select a:hover strong, 
.leftNav .select li:hover a strong {
display:block; 
float:left; 
padding:0 20px 0 20px; 
background:#aaaaaa;
cursor:pointer;
}

.leftNav .select_sub {
display:none;
}

    /* IE6 only */
.leftNav table {
border-collapse:collapse; 
margin:-1px; 
font-size:1em; 
width:0; 
height:0;
}

.leftNav .sub {
margin:0 auto; 
padding:0; 
list-style:none;
font-weight:bold;
}

.leftNav .sub_active .current_sub a, 
.leftNav .sub_active a:hover {
background:transparent; 
color:white;
}

.leftNav .select :hover .select_sub, 
.leftNav .current .show {
display:block; 
position:absolute; 
top:58px; 
background:#60a74a; 
padding:0; 
z-index:100;
left:-100px;/*this is the alignment for the submenu*/ 
float:left;
}



.leftNav .current .show {
z-index:10;
}

.leftNav .select :hover .sub li a, 
.leftNav .current .show .sub li a {
display:block; 
float:left; 
background:transparent; 
padding:0 20px 0 20px; 
margin:0; 
white-space:nowrap; 
border:0; 
color:white;
}

.leftNav .current .sub li.sub_show a {
color:white; 
cursor:default; 
background:#60a74a;
}

.leftNav .select :hover .sub li a:hover, 
.leftNav .current .sub li a:hover {
visibility:visible; 
color:white; 
background:#aaaaaa;
}

.leftNav .select :hover .select_sub, 
.leftNav .current .show {
display:block; 
position:absolute; 
top:58px; 
background:#60a74a; 
padding:0; 
z-index:100;
left:0;/*this is the alignment for the submenu*/ 
float:left;
}

Answer №1

Welcome to the wonderful world of Stack Overflow! One way to enhance your .sub element (select_bg) is by adding an additional div and adjusting its positioning using properties like margin-top and z-index:

Check out this JSFiddle for a demonstration: http://jsfiddle.net/wQs5a/1/

This approach may not be perfect as it requires working with specific dimensions, but the good news is that you can achieve the desired effect without having to rely on JavaScript. :)

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

I prefer to have the links activate when the mouse hovers over them, rather than when hovering over empty

Is there a way to prevent the bottom links (music, contact, archive) from being highlighted when the mouse hovers over the empty space between them and not just on the actual links themselves? I want the mouse to only react to the links it hovers over and ...

Eliminate the "::before" CSS styling

https://i.sstatic.net/zTBhR.png The header of my blog post on blogger currently has a unwanted "-" element that I would like to remove. This element is created using a ::before in the CSS. I followed advice from this source and attempted to add the followi ...

Removing a JQuery Element Upon Parent Position Adjustment

I'm currently working on a website that features a sticky navbar, and I'm trying to implement a symbol that appears when the navbar reaches the very top of the page as the user scrolls down. However, I'm encountering an issue where the symbo ...

Tips for styling jqgrid header columns with CSS

Currently, I am creating a table using jqgrid. One of my objectives is to modify the background color and text color of the header. In my attempts to achieve this, I am experimenting with applying a class to the header. How can I effectively implement th ...

Define the total in a CSS attribute

I am working with multiple divs that have a specific CSS class applied to them. My goal is to manually increase the pixel value in the top property: .class { top: 100px; } div class="class" style="top:+=50px" Is it possible to achieve this functiona ...

Determine the total quantity of colored cells within a row of an HTML table and display the count in its own

I need assistance with a table that has 32 columns. From columns 1 to 31, I am able to fill in colors by clicking on the cells. However, I now want to calculate and display the number of cells that are not colored in the last column. This task must be co ...

Setting the CSS position to fixed for a dynamically generated canvas using JavaScript

My goal is to fix the position style of the canvas using JavaScript in order to eliminate scroll bars. Interestingly, I can easily change the style using Chrome Inspector with no issues, but when it comes to implementing it through JS, I face difficulties. ...

A step-by-step guide on how to display a specified amount of images in the center of

I'm currently working with a div that displays images dynamically loaded from a database, ranging from 1 to 5 images. The number of images may vary each time, and I need assistance in centering these images inside the div regardless of their quantity. ...

Using HTML and CSS to create nested divs floating to the left while also incorporating a

I'm trying to create a simple effect where a fixed height and width div contains a series of child divs that can be scrolled horizontally. However, the children are not floating as expected in the following code: .a {width:200px; height:200px; ...

What techniques can I employ in HTML and CSS to design the user interface for my Java application?

Recently, I came across an interesting article at this link: http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm. The article demonstrates how to develop a java application utilizing the javafx library and utilizing classes like WebEngine and WebVie ...

What could be the reason for the CSS file not getting applied to the HTML in my project?

Having trouble applying an external CSS file to my HTML file. Currently working on a Cloud IDE (goormIDE, similar to C9) and trying to link an external CSS file to my HTML file on the web server using Node.js. However, the CSS file is not being applied to ...

Animating slides with CSS Keyframes and React, incorporating toggle slide fade out and slide fade (back) in

I am seeking a solution for toggling a box (div) with slide-out animation and then sliding back in animation (in reverse) upon button press. My requirement is to have no animations during the initial page render. While I can successfully slide the box to ...

optimal application of css with jquery

I have a question about using jQuery to set the padding of a class or id. I am able to successfully change the height of an element with this code: $('.menu').css({ height: '90px' }); But now, I need to apply a specific CSS rule in jQ ...

The v-bind class feature is failing to update the CSS on the object's properties

I'm attempting to dynamically modify the CSS of certain buttons based on object properties within a list. Below is the data I am rendering out, and despite following the documentation and ensuring my setup is correct, I seem to be overlooking somethin ...

Tooltips on dynamic dropdown lists in web forms

I am facing an issue with my cascading dropdowns for topics and sections. I wanted to use tooltips to display the description of each topic and section, but I am running into problems. The tooltip only shows up after selecting a topic or section, and the d ...

Challenge with the continuity of my Html/CSS coding

I am currently expanding my knowledge in web development with a focus on CSS. While I am familiar with JS and HTML, CSS is proving to be more challenging for me. I have been attempting to create a webpage using Bootstrap, but I have hit a roadblock with th ...

Achieving vertical alignment of content within a card using Bootstrap

Can someone help me create a card similar to this design? Example Card I'm having trouble aligning the items at the bottom like in this example: My Card Here is my code snippet: <div class="container"> <div class="row row ...

Implement the text-overflow: ellipsis style in a <li> element to truncate text after two lines

I need help with creating a list where each item has a dynamic length. The maximum amount of lines for each item should be 2, and if the text overflows those 2 lines, it should end with dots. I know that using "white-space: nowrap;" can prevent wrapping, b ...

What could be causing the unexpected behavior of display:initial?

I have a child image that is initially hidden, but shows up when someone hovers over the parent image. The issue I am facing is that when the child image appears, it does so on the right-hand side of the parent image. I was under the impression that it wo ...

I'm having trouble displaying my background image unless I specifically set the height in pixels or viewport height

I have been working with ReactJS and on my main page container, I am setting a background image like this: .opening-container { background-image: url("../../images/sadaqashdbg.png"); background-position: center; background-size: cover; ba ...