Change Styles Of Element When Another Element Is Active

how to make hovering over one div to trigger changes in another div
css active not working
button:active css
active pseudo element
scss active button
css child selector
css button active not working
active button state

can i change the style of class 1 when class 2 is focus or hover? is there any way do this with css?

like here.
<button class='class 1'></button>
<button class='class 2'></button>

Try this


    <button class='class1'>button1</button>
    <button class='class2'>button2</button>


    .class1:hover + .class2,
    .class1:active + .class2,
    .class1:focus + .class2{
          background: blue;

    .class2:hover + .class1,
    .class2:active + .class1,
    .class2:focus + .class1{
          background: green;

Thank you.

:hover, It is generally triggered when the user hovers over an element with the cursor Styles defined by the :active pseudo-class will be overridden by any the user has stopped touching and until the user touches another element. A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :hover selector to style links when you mouse over them.

You can do it using mouseover and mouseout

$('.class').on('mouseover', function(e) {


$('.class').on('mouseout', function(e) {

.hover {
  background: green;
<script src=""></script>
<button class='class 1'>Test</button>
<button class='class 2'>Test 1</button>

:active, In CSS, pattern matching rules determine which style rules apply to elements in the The link pseudo-classes. E:active. E:hover. E:focus, Matches E during certain element that is the descendant of another element in the document tree (e.g., Although the intention of these rules is to add emphasis to text by changing its� Select the element whose style properties needs to be change. Use property to set the style attribute of an element. Set the properties either by using bracket notation or dash notation. Example 1: This example changing the color and background-color of heading element.

Try this. It will change the bg color of button 1 when button 2 is hovered on

$(document).ready(function() {
  $('.class2').hover(function() {
    $('.class1').css('background-color', 'blue')},
    $('.class1').css('background-color', '')
<script src=""></script>
<button class='class1'>Button</button>
<button class='class2'>Button</button>

Selectors, Example. Select and style every <p> element that are placed immediately after < div> elements: div + p { background-color: yellow; }. Try it Yourself �� At times you may wish to move an element from one level to another, or to copy an element to other levels. The following procedures show you how to copy and move elements between levels. To change an element's level using the Active Level combo box. Select the element whose level you want to change. Click the Active Level combo box.

This is possible using only CSS, but it can be a bit finicky.

You could use pseudo-classes focus and hover and select the immediately after element with the class .class1. Since + will target the element immediately after you can use flex and order to move your buttons around so they appear in the correct order:

.class2:hover+.class1 {
  background: lime;
  color: red;

.class2:focus+.class1 {
  background: red;
  color: white;

.wrapper {
  display: flex;

.class1 {
  order: 1;

.class2 {
  order: 2;
<div class="wrapper">
  <button class='class2'>Button2</button>
  <button class='class1'>Button1</button>

CSS element+element Selector, <div class="sibling-hover">hover over me</div>. 4. <div>I do nothing</div>. 5. < div>I do nothing</div>. 6. <div class="sibling-highlight">I get highlighted</div>. 7. Is it possible to define a CSS style for an element, that is only applied if the matching element contains a specific element (as the direct child item)? I think this is best explained using an example. Note: I'm trying to style the parent element, depending on what child elements it contains. <style> /* note this is invalid syntax.

You can try with jQuery's .hover().

Please note: class names do not allow space in them.

  function() {
  }, function() {
<script src=""></script>
<button class='class1'>Button 1</button>
<button class='class2'>Button 2</button>

Change another element on :hover - JSFiddle, butmore has a class of active after it is clicked, then change <header> to position: relative . Otherwise it is position:fixed . The styling is already� How to affect other elements when one element is hovered (6 answers) Closed 9 months ago . When I hover over a div or class with an id of "a", can I get the background color of a div or class with the id of "b" to change?

Change CSS of One Element Based on Class of Another Element , Learn how to use Chrome DevTools to view and change a page's CSS. The Styles tab on the Elements panel lists the CSS rules being applied to whatever element is currently DevTools supports :active , :focus , :hover , and :visited . It is also possible to use setAttribute to modify the class of an element. Modifying Styles. The style property repesents the inline styles on an HTML element. Often, styles will be applied to elements via a stylesheet as we have done previously in this article, but sometimes we have to add or edit an inline style directly.

Get Started With Viewing And Changing CSS, Why you should (and how to) style hover, focus, and active states differently. : hover triggers when a user brings their mouse over an element. color */ } . element:active { /* Another change in background/text color� Using a select element to change the active stylesheet for a web page. This page demonstrates the use of a select element to change the active stylesheet for a web page. It also provides step by step instructions on how to create the select element. Instructions. Add a link element to the head of your web page.

Style hover, focus, and active states differently, With pseudo-classes, we can select elements using information that isn't already in the DOM and can change based on how a user interacts with the page. the element and, importantly, it will continue to stay in focus until the user activates another element. Order of styles - :hover then :focus then :active. Instead, :hover styles are applied when the user has touched an element, and removed when he touches another element. The same problem goes for :active, and there is no way to show active styles on elements other than links on touchscreen devices.