Is it possible to disable hovering effects on inner elements?

Disable the hover pseudo-class on child elements. Prevent the hover effect on child elements when hovering over them. Is there a way to achieve this?

.link:hover {
  background: #499a75;
}
<a href="#" class="link">
  Test
  <ul>
    <li>1</li>
    <li>2</li>
  </ul>
</a>

Answer №1

If you are using javascript, you have the ability to verify whether the event target matches the specific element where you want to implement an effect. If it does, then add a certain class; if not, remove it.

var link = document.querySelectorAll('a.link')[0];
link.addEventListener('mouseover', mouseEnter, false);
link.addEventListener('mouseout', mouseLeave, false);

function mouseEnter(event) {
    if(event.target === link) {
        link.classList.add('hover');
    }
    else {
        mouseLeave();
    }
}

function mouseLeave() {
    link.classList.remove('hover');
}
.link.hover {
  background: #499a75;
}
<a href="#" class="link">Example Text
    <ul>
        <li>1</li>
        <li>2</li>
    </ul>
</a>

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

Using box-shadow with table rows

I am encountering an issue trying to add a box-shadow to tr elements within a table. The problem arises when the box-shadow does not display unless all the tr elements are set with a display property of block, as suggested in this workaround: Box Shadow in ...

What is causing the colored SVG to appear lighter than the intended color after using a mask to recolor it?

I have a project using VueJS where I am trying to change the color of SVGs by looping through them and using mask and rect tags. However, I am noticing that as the icon index increases, the color of the icon becomes lighter. What could be causing this issu ...

Unable to get CSS First Child Pseudo Element to Work Properly

I'm having trouble with this code in CSS and would appreciate any help. I can't figure out why the margin-left won't apply to the first i element. Below is the CSS I'm using: header.site-header .right_side_menu i:first-child { marg ...

preferring images to be positioned side by side rather than stacked underneath each other

I am facing a challenge in arranging the images on my Tumblr site to display side by side instead of stacking one on top of the other. Despite multiple attempts at following advice from various forums, I have been unsuccessful in achieving the desired layo ...

Using JavaScript, generate ten clickable circles on the screen. Each circle should display the number of times it has been clicked in the center when interacted with

I am currently working on my JavaScript skills and would like to implement a fun project involving 10 colorful circles. While I can easily create these circles using HTML and CSS, I require assistance with the interactive functionality using JavaScript. ...

Incorporating an icon into a Bootstrap tab

I have encountered a minor issue while trying to include an icon in a bootstrap tab, resulting in some styling problems. In need of a CSS resolution that satisfies the following criteria: The icon must be aligned to the right of the link. The icon canno ...

Creating a grid cell that spans the entire grid width

Snippet of CSS Code: .wrapper { display: grid; position: relative; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 25vh; width: 100%; } .prova { border: 1px solid; } .wrapper div:nth-child(2) { grid-column: 3; grid-row: 2 / 4; ...

``Protect your PDF Document by Embedding it with the Option to Disable Printing, Saving, and

Currently, I am facing a challenge to enable users to view a PDF on a webpage without allowing them to download or print the document. Despite attempting different solutions like Iframe, embed, PDF security settings, and Adobe JavaScript, I have not been s ...

Having trouble positioning text alongside a checkbox in Bootstrap v3.3.6?

Dealing with the alignment of checkboxes in Bootstrap forms is driving me crazy. It seems to look almost perfect on both Chrome and IE on my desktop, where the text and checkbox are aligned almost perfectly. However, when I view it on Chrome on my tablet ...

What is the reason behind the constraints of min/max width and height values preventing the element from fully filling its parent div?

HTML Code: <div class="content"> <div class="card"> </div> </div> CSS Code: .content { min-height: 350px; min-width: 320px; max-width: 350px; padding: 15px; } .card { width: 100%; height: 100%; ...

Changing the font-family to 'Symbol' and using Windows-1252 character encoding

I have a collection of HTML documents that contain basic text encoded in Windows-1252, but scattered throughout the content are various instances of span elements styled with font-family: Symbol. For instance: <span style='font-family:Symbol& ...

What causes the html5 <audio> tag to appear differently on Chrome versus IE browsers?

When viewed in Chrome, the design appears clean and compact, but when seen in Internet Explorer, it looks large and overwhelming. Check out the screenshots below.. Do you have any suggestions to fix this issue? Know of any mp3 hosting platforms with an emb ...

What are some solutions for resolving differences in the display of pseudo elements between Macbooks and Windows desktops?

Greetings! I successfully converted an XD file to HTML and CSS code. I tested it on my Windows PC, but I haven't had the chance to test it on a Macbook yet. Details: I implemented a button with a pseudo element to show a right arrow on the right side ...

Steps to align an SVG to the right within a div

I'm struggling to get an SVG to align at the end of its containing div. The div is set to display in flex and I've tried using "align-self: flex-end" on the a tag that wraps the svg, as well as experimenting with block and float-right. Any sugges ...

Verify if a background image has been designated

Currently, I am working on a basic script that involves file input to change the background of a website to a specific image. The script is functioning as intended, but I encounter an issue when I refresh the site - the background image disappears. I am l ...

Should you prioritize internationalizing your image alt attributes?

Do you localize your alt attribute in img tags for internationalization? Is it beneficial in the long run? ...

I am currently facing an issue with retrieving the class value that is being generated by PHP code

I am currently facing an issue with jQuery and PHP. Whenever I attempt to target the click event on the class ".id_annonce" in the dynamically generated PHP code, it doesn't retrieve the exact value of what I clicked. Instead, it always gives me a fi ...

Angular 14's "rootItem" animation trigger was created with the following alerts: - The properties listed below are not animatable: overflow

Upon upgrading to Angular 14, I encountered this warning. The properties mentioned are not actually used in my animations. [Error in console][1] The animation triggers "rootItem" has been built with the following warnings: - The following provided propert ...

Automatically add a table row at the bottom displaying the overall calculation

I have data to display in an HTML table. The data is coming from a third-party server (PHP) using AJAX requests. The data is currently being displayed effectively with the following code: <table id="tbl-product"> <tr> < ...

"An issue with preventing default behavior when clicking on a jQuery element

I need some assistance preventing a JQuery onclick function from scrolling the page to the top. I have tried using preventDefault() without success. You can find the code on this website: Below is the code snippet that I am currently using: $( document ...