Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:35:37+00:00 2026-05-16T21:35:37+00:00

I have a structure of div s inside div s, something like: <div> <div>

  • 0

I have a structure of divs inside divs, something like:

<div>
    <div>
        <div class='a'>Hello</div>
        <div class='a'>Stack</div>
        <div>Overflow</div>
    </div>
    <div>
        <div>You</div>
        <div class='b'>Are</div>
        <div class='b'>The Best</div>
    </div>
    <div>
        <div>Have</div>
        <div class='b'>a nice</div>
        <div>Day !!</div>
    </div>
</div>

I would like all divs with class a to change the background color when one of them is hovered by mouse. The same for all divs with class b: when one of divs with class b is hovered, all divs with class b should change the background color.

Is that possible to implement this behavior without Javascript ?

If the answer is no:
Is that possible if known that all divs with class a are consecutive divs in the same level (i.e. siblings) ?

I can add also other classes to divs, if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:35:37+00:00Added an answer on May 16, 2026 at 9:35 pm

    You can get it “half working” in the simpler case where there are no container <div>s:

    <div>
      <div class='a'>Hello</div>
      <div class='a'>Stack</div>
      <div>Overflow</div>
      <div class='b'>Are</div>
      <div class='b'>The Best</div>
      <div>Have</div>
      <div class='b'>a nice</div>
      <div>Day !!</div>
    </div>
    

    Then you could use the general sibling combinator, with the unfortunate caveat that it only works for elements that come after the element described on the left-hand side. So, for example, if you hovered over the <div> containing “The Best”, only that and the “a nice” <div> would have a changed background:

    div.b:hover, div.b:hover ~ div.b {
        background-color:#CCCCCC;
    }
    

    I wasn’t able to come up with a way that would fully take care of your scenario through CSS alone, though. I’m leaning towards what the others have said about it not being possible (even in the simplified case) right now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure of div s inside div s, something like this: <div
I have a structure of html like this: <div id="triger1">some elements inside</div> <div id="triger2">some
I have a table structure that looks like: <table> <tr id=row1> <td> <div>row 1
I have one html structure , somethinh like <div> <div id=mydiv> <h3> This is
i have the following div structure with respective ids : <div id=border_1 class=track_mc01302 track_01_mc01302>
If I have a structure like this: <div id=main> <div id=sidebar> <div id=tag-cloud/> </div>
I have html structure <div class=div> <img src=img1.jpg class=img /> </div> How do I
I have this HTML structure and want to convert it to an accordion. <div
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.