Hover effect that transforms every element of the same kind except for the one that is currently being

Is it possible to create a hover effect that changes not only the hovered "a" tag but also other "a" tags? Currently, I can only achieve the desired effect on the selected hover.

ul li{
  list-style: none;
}
ul li a {
   color: black;
}
ul li a:hover{
   color: green;
   background: orange;
}
ul li a:hover:not(a:hover){
   color: red;
   background: black;
 }
 <ul>
   <li>
     <a>test</a>
   </li>
   <li>
     <a>test</a>
   </li>
   <li>
     <a>test</a>
   </li>
 </ul>

I'm aiming for a hover effect where the selected link turns green with an orange background while the other links become red with a black background.

Answer №1

Is it possible to create a hover effect for all items within a ul element, making them black and red, and then customize the hover effect for each individual item?

ul li{
  list-style: none;
}

ul:hover li a {
   color: red;
   background: black;
}

ul li a {
   color: black;
}

ul li a:hover{
   color: green;
   background: orange;
}
<ul>
   <li>
     <a>test</a>
   </li>
   <li>
     <a>test</a>
   </li>
   <li>
     <a>test</a>
   </li>
  </ul>

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

Does anyone else have a peculiar problem with css width?

Either I have been designing web pages for an extensive period of time without taking a break or something truly bizarre occurred. <div style="background-color:#0F0; margin:5px; height:5px;"></div> This will generate a lengthy bar with a 5-pi ...

Positioning a material UI dialog in the middle of the screen, taking into account variations in its height

Dealing with an MUI Dialog that has a dynamic height can be frustrating, especially when it starts to "jump around" the screen as it adjusts to fit the content filtered by the user. Take a look at this issue: https://i.stack.imgur.com/IndlU.gif An easy f ...

Optimal banner image dimensions for responsive mobile display on various devices

What is the best way to ensure a banner image looks good on small and medium mobile devices, as well as tablets? ...

The Body and HTML elements compress to sizes significantly smaller than the viewport

I am currently working on making my WordPress website responsive. On one of the pages, I have two images that I want to set a max-width of 100% to ensure they are responsive. However, when I shrink the page in Chrome dev tools, I noticed that the <html& ...

Create two div elements containing responsive images using HTML and CSS

Can someone assist me in creating responsive DIVs with images inside? Currently, the second div is appearing below the first one, and I'm struggling to make them scale based on mobile and tablet screen sizes. Here is the code snippet: .new_ba ...

Utilizing SASS with Bootstrap 4 media breakpoints: A comprehensive guide

According to the information provided on the official Bootstrap website: Bootstrap writes its source CSS in Sass, making all media queries available via Sass mixins: @include media-breakpoint-up(xs) { ... } @include media-breakpoint-up(sm) { ... } @in ...

Getting the full referrer URL can be achieved by using various methods depending

I am currently working with ASP.Net. My goal is to retrieve the complete referrer URL when visitors arrive at my website from: https://www.google.co.il/webhp?sourceid=chrome-instant&rlz=1C1CHEU_iwIL457IL457&ion=1&espv=2&ie=UTF-8#q=%D7%90 ...

jQuery is mistakenly showing a width of zero

When attempting to determine the width of specific elements using jQuery's .width() function, I occasionally encounter a return value of 0 unexpectedly. Could this be a common problem? Is it possible that an element must be visible in order for this f ...

Are your divs getting truncated?

Currently faced with a perplexing issue where inserting elements into a div causes scaling problems, resulting in most of the divs being cut off. This glitch occurs when two new elements are added. Despite changing page sizes and thoroughly debugging by o ...

Step-by-step guide on triggering a button using another button

I have a unique question that sets it apart from others because I am looking to activate the button, not just fire it. Here is my syntax: $("#second_btn").click(function(){ $('#first_btn').addClass('active'); }) #first_btn ...

Default Slider Features

I am in need of assistance to create a slider similar to this example. Can anyone help me with this? <link type="text/css" href="ui.all.css" rel="stylesheet" /> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script ...

Absolute Positioning Problem

When I attempt to insert elements as static html text, everything functions correctly. However, when I try to insert elements at runtime (using arrays of data from the server), I encounter positioning issues with absolute. Here is the simplest example to r ...

Issues with maintaining row column format in Bootstrap cards

I am currently facing an issue with the layout of my template: <center> <form class="site-form" action="{% url 'movie:recommend'%}" method="post"> {% csrf_token %} <input style="font-color:#000000;color: #008 ...

Tips for positioning an inner div within an outer div

Code Snippet: <div style="width: 300px; position: absolute; right: 25%; top: 5%; -webkit-box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75); -moz-box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75);box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75);"> <secti ...

On one webpage, IE 11 is correctly styling certain visited hyperlinks while failing to do so for others

Although I acknowledge that others have asked similar questions, none seem to address the exact issue I am facing, nor do they offer practical solutions or clear explanations. Issue I'm encountering a problem where some visited hyperlinks in IE 11 f ...

Apply a specific class to the input field when the name matches x

I have a website that loads a JavaScript file from a commercial service, so I am unable to customize this file. The output of this JavaScript file is a form with various input fields, all of which have the class name "wf-input". I now want to add a jQuery ...

What is the best way to eliminate the underline text decoration from a link element?

Take a look at this JS Bin. I want to change the link Project name in there. By default, it is underlined when hovered over. How can I remove that effect? I attempted using a class project-name: a:hover, a:focus .project-name { text-decoration: non ...

The pseudo element 'not' in CSS is currently not functioning as expected when applied to an anchor tag

When working with CSS, I encountered an issue while trying to apply a pseudo element on hover and active states of anchor tags. Unfortunately, my code was not producing the desired outcome. a:not(a[name="nobgcolor"]):hover{color:#ffff35;background-color:# ...

What could be the reason for my CSS animation with :hover @keyframes not functioning?

As a newcomer, I am struggling to understand why this code isn't functioning correctly. My goal is to create the illusion of a flying bird. This is my HTML: <img src="http://dl.dropboxusercontent.com/u/105046436/tw.png" /> <br> <div c ...

Shift the position of an element horizontally when another element is being hovered over

Attempting to create a unique swiper slider using CSS, here is what has been accomplished so far in terms of HTML: <section id="lakeSlider" class="carousel vcenter-item py-5"> // More HTML code here </section&g ...