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 6714715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:41+00:00 2026-05-26T08:31:41+00:00

Let’s say I have three div elements with classes a , b , and

  • 0

Let’s say I have three div elements with classes a, b, and c, respectively. I want to use css to toggle the display of these elements between none and block, depending on whether or not a parent element has a class of current or is hovered. The elements always toggle together, never individually.

I can a) toggle the display on the elements individually, or I can b) wrap them in a fourth div that is otherwise non-functional and toggle display on that element instead.

So, for instance, it’s this:

<li>
  <div class="a"></div>
  <div class="b"></div>
  <div class="c"></div>
</li>

li > .a,
li > .b,
li > .c {
  display: none;
}

li:hover > .a,
li.current > .a,
li:hover > .b,
li.current > .b,
li:hover > .c,
li.current > .c {
  display: block;
}

versus this:

<li>
  <div class="wrap">
    <div class="a"></div>
    <div class="b"></div>
    <div class="c"></div>
  </div>
</li>

li > .wrap {
  display: none;
}

li:hover > .wrap,
li.current > .wrap {
  display: block;
}

There’s an obvious code-cleanliness difference in the css, at the expense of some additional html structure, but I think the net is in favor of using the wrapper.

I’m wondering if there are any other benefits or costs, such as browser performance, one way or the other between the two options.

  • 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-26T08:31:41+00:00Added an answer on May 26, 2026 at 8:31 am

    Actually, you don’t have to do either :). You’re using CSS!! Consider the following:

    <!-- Notice the space between the class names -->
    <li class="switch">
        <div class="a toggle"> ... </div>
        <div class="b toggle"> ... </div>
        <div class="c toggle"> ... </div>
    </li>
    

    Now, you can keep your styling elements for a, b, c. By adding a simple CSS style, you can cover both of your sets of needs quickly and easily. Additionally, its abstracted, so you could use it in more places, when needed. No addition of DOM elements necessary and no real changes to your current styling code for a, b, and c. Furthermore, your switch doesn’t even have to be an li.

    .switch:hover > .toggle,
    .switch.current > .toggle { display:block;
    }
    

    Additional Information on CSS classes

    Elements may be of more than one class. By utilizing this, you can separate pseudo-functionality from look inside your CSS. When utilizing multiple classes, the browser will combine the rules of both to complete its style.

    Consider the following:

    <body class="article twocolumns">
    
    • The body element will have whatever html positioning, and overall document overrides.
    • The article class would have whatever presentation styles you might need.
    • The twocolumns would have whatever layout parameters your require.

    You may provide individual or combination styles, like so:

    body { 
        margin:0 auto; 
    }
    .article { 
        background-color:white;
    }
    .twocolumns {
        background-image: url("divider.png");
    }
    
    /* This is a combination style. Notice no space between the two classes. */
    .article.twocolumns > div { 
        padding:15px; 
        float:left; 
        width:50%; 
    }
    /* A possible further extension. */
    .article.onecolumn > div {
        padding:20px; 
        float:none; 
        width:100%; 
    }
    .article.threecolumn > div { 
        padding:10px; 
        float:left; 
        width:33%; 
    }
    

    Learning to do things in this way has a number of benefits. It allows you to abstract functionality, layout and presentation elements easier allowing you to “port” either to other web projects you might have. It allows you to find what works cross-browser more effectively for more unified look and feel. It also reduces the tendency to accidentally tweak rules that might not be related to your issue. Finally, it reduces your dependency on extraneous DOM elements allowing you to keep your performance.

    Hope this helps.
    FuzzicalLogic

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

Sidebar

Related Questions

Let's say I have a drive such as C:\ , and I want to
Let's say I have some content classes like Page, TabGroup, Tab, etc. Certain of
Let's say I have two files.. I want to compare them side-by-side and see
let's say i have three tables, each one relates to another, when i need
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have the following within my source code, and I want to
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,

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.