Is there a way to modify the background hue of an upward facing triangle when a submenu is hovered over?

Access the Code on Fiddle

#nav .submenu:before {
   content:"";
   position: absolute;
   width: 0;
   height: 0;
   border-bottom: 22px solid #b29600; 
   border-left: 11px solid transparent; 
   border-right: 11px solid transparent;    
   margin: -12px 0 0 -55px;
}

The codes have been shared on jsfiddle for reference. The issue at hand involves a hover effect on main menus that displays submenus with an upward triangle marker. However, when hovering over submenu 1, the background color changes but the upward triangle remains unchanged. How can I modify the code to update the color of the upward triangle in sync with the submenu background?

Answer №1

Experience a unique way to modify the Triangle Color as you navigate through our submenus.

#nav .submenu:hover:before {  border-bottom: 22px solid #4C4000; }

To customize the color specifically for the First option in the submenu, jQuery can be utilized.

Answer №2

Would you be open to trying a JavaScript solution? You can modify the class on hover to change the color of the triangle.

Check out this demo: http://jsfiddle.net/lotusgodkk/buLy7/1/

$(document).ready(function () {
$('.submenu li a').on('mouseover', function () {
    $(this).parents('.submenu:first').addClass('temp');
});
$('.submenu li a').on('mouseleave', function () {
    $(this).parents('.submenu:first').removeClass('temp');
});
});

I've used the class temp to handle the color changes.

CSS:

#nav .submenu.temp:before {
 border-bottom: 22px solid red;/*Your color*/
}

In case there are multiple submenus: JS:

$(document).ready(function () {
$('.a').on('mouseover', function () {
    console.log('in');
    $(this).parents('.submenu:first').addClass('temp');
});
$('.a').on('mouseleave', function () {
    $('.temp').removeClass('temp');
});
});

HTML:

<div id="nav">
<ul>
    <li><a href="#">Main</a>

        <ul class="submenu">
            <li><a class="a" href="#">Sub 1</a>

            </li>
            <li><a href="#">Sub 2</a>

            </li>
            <li><a href="#">Sub 3</a>

            </li>
            <li><a href="#">Sub 4</a>

            </li>
        </ul>

    </li>
     <li><a href="#">Main</a>

        <ul class="submenu">
            <li><a class="a" href="#">Sub 1</a>

            </li>
            <li><a href="#">Sub 2</a>

            </li>
            <li><a href="#">Sub 3</a>

            </li>
            <li><a href="#">Sub 4</a>

            </li>
        </ul>

    </li>
</ul>
</div>

Changes made:: Added a class to the first anchor in .submenu and then attached events to it.

Answer №3

By relocating the pseudo-element to the first-child LI, you can easily implement it using CSS. Here is an example:

#nav .submenu li:first-child:before {
   content:"";
   position: absolute;
   width: 0;
   height: 0;
   border-bottom: 22px solid #b29600; 
   border-left: 11px solid transparent; 
   border-right: 11px solid transparent;    
   margin: -12px 0 0 -0px;
}

#nav .submenu li:first-child:hover:before {  border-bottom: 22px solid #4C4000; }

http://jsfiddle.net/36yqr/

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 am looking to transform col-sm-4 into two evenly sized columns with one row at the bottom using Twitter Bootstrap

Hello there, I have successfully created three columns in one row with column sizes of col-sm-4 each. Each column is further split into two equal sections and includes a footer row. You can see the alignment in the image below: Check out this sample align ...

Exploring search results using dynamic multiple dropdown lists in PHP

Be sure to check out this interesting link: There are six drop down boxes available on the page. These include options for STATE, DISTRICT, LOCATION, MEDICINE, SPECIALTY, and GRADE. I successfully retrieved all the necessary data from the SQL database to ...

A different way to center elements using CSS

Many criticize the center tag, but I find that it consistently aligns things perfectly for me. Despite its deprecation, I still rely on it. I've come across suggestions to use the mysterious CSS margin: 0 auto;, but I struggle to make it work (refer ...

Optimizing the display of multiple list items using Javascript for two separate UL elements on a single webpage

How can I display a maximum of 5 list items in two separate UL elements on the same page and hide the rest? Users should be able to see more items by clicking a dynamic "See more" element created by JavaScript. Below are the UL elements I want to work wit ...

What is the best way to manage div visibility and sorting based on selections made in a select box?

Explaining this might get a bit confusing, but I'll do my best. In my setup, I have two select boxes and multiple divs with two classes each. Here is what I am trying to achieve: When an option is selected, only the divs with that class should be ...

Activate tooltip when hovering over the <img> element

I am having trouble implementing a tooltip using CSS for an <img> element. While I have successfully added a tooltip to <a href> </a> tags, applying the same functionality to an <img> tag has proven difficult. http://jsfiddle.net/ ...

Would it be expected for these two JQuery functions to exhibit identical behaviors?

If I have the following two JQuery functions - The first one is functional: $("#myLink_931").click(function () { $(".931").toggle(); }); The second one, however, does not work as expected: $("#myLink_931").click(function () { var class_name = $(thi ...

multiple server-side tables with toggle buttons

I'm struggling with a page that contains 3 tables using datatables. The issue is that datatables can't handle more than one table, and after searching for a solution, I found a customized SSP Datatables at this link: here However, I'm wonde ...

The POST variable comes up empty when making an AJAX request

I am currently attempting to utilize an AJAX call to POST the selected value from a dropdown list. However, I am encountering an issue where the POST variable is coming back empty once a value is chosen from the dropdown. In order to troubleshoot this pro ...

Using JQuery to Customize Navigation Menu Targeting

On my website, I am trying to make an href button and a menu fade in as the page loads. However, I am struggling to find the correct code due to its placement within multiple tags, especially since I am new to JS and JQuery. I have provided a fiddle with a ...

Creating input fields using Bootstrap HTML on a single line

Struggling with Bootstrap, I can't figure out how to display the following HTML inputs in a single line: <div class="row"> <div class="col-sm-8"> <div class="form-group"> <input class="form-control" ...

When transformed into clickable links, the list items start piling up on

Here are two groups of code along with a straightforward question that most people can answer easily, but still worth asking. Below is the initial piece of code with working CSS implementation: <div class="subTopHolder"> <ul class="language ...

Get an array of JSON values using a jQuery function

How can I create a jQuery function that imports a JSON value and returns an array when called? I have written the following function, but it is returning an empty array. The JSON file I am working with is very basic, similar to this example: { "fruit": [ ...

"Introduce a time delay for the hover effect on the navigation dropdown

I've been struggling to find a way to add a delay to this hover effect. If you visit , you'll see a menu at the top that displays panels when hovered over. The CSS code to make them appear is: #navigation li:hover > .panel { display: blo ...

Tips for Sending an Ajax POST Request

I've been using the following code snippet to initiate a POST request to my node API in order to generate a PDF. However, upon execution, my node console displays the following errors: $('#renderPDF').click(function(){ var request = $ ...

Position the button at the bottom of the page with MUI v5 in a React application

How can I ensure the button is always positioned at the center bottom of the page, regardless of the content height? This is a snippet from my code: const useStyles = makeStyles({ button: { bottom: 0, right: 0, position: "absolute" ...

Align text in the middle using CSS

I want to apply the following css styles #header { color: #333; width: 900px; float: left; padding: 10px; border: 1px solid #ccc; height: 150px; margin: 10px 0px 5px 0px; background-image: linear-gradient(to top, #CACACA 0%, #EFEFEF 100%); } With ...

Positioning an absolute div inside a relative div within a v-for loop while using VueJS and Element UI

I am experimenting with rendering a list of <el-card> items using a transition-group. Each card has a front and back side that flip when a button is clicked. To achieve a smooth flip transition, I need to apply the style: position: absolute; top: 0; ...

Placing buttons on top of a video within a div container

I am facing a challenge with implementing custom controls on a video embedded in my webpage. I have tried setting a div to absolute position for the buttons, but they are not clickable. Is there a way to achieve this without using jQuery? I need the butto ...

Retrieve the current element's 'this' object even after binding an external 'this' object

Is the title of this question confusing? Let's dive in. Imagine you have something like this: var Test = function(){ this.foo = a; } Test.prototype.init = function() { $(document).on('change', '.form-control', this.myFun ...