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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:08:09+00:00 2026-06-14T23:08:09+00:00

Consider this HTML with CSS classes aa , bb and cc : <div class=’aa’>

  • 0

Consider this HTML with CSS classes aa, bb and cc:

<div class='aa'>
<div class='bb'>
<div class='cc'>
</div>
</div>
</div>

I can select the class=cc tag like so: .aa > .bb > .cc. However, in my case, sometimes the .bb tag is absent, that is, the HTML looks like so:

<div class='aa'>
<div class='cc'>
</div>
</div>

Thererfore, to select all .cc close to an .aa, I’d need to specify two CSS paths:

.aa > .bb > .cc,
.aa > .cc { .... }

This works, but, is there no shorter way? Something similar to this:

.aa > (.bb >)? .cc { ... }   /* ? means "optional" */

with CSS or something like Stylus or LESS?

Motivation: In the real world, “aa” and “bb” and “cc” are somewhat longer names, and there’s more stuff before and after the “aa” and “cc”, and it’d be nice to not need to duplicate that stuff.

Please note: In my case, this won’t work: .aa .cc because that’d match too many .ccs elsewhere on the page. The .ccs need to be either immediately below the .aa, or below .aa > .bb.

  • 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-06-14T23:08:10+00:00Added an answer on June 14, 2026 at 11:08 pm

    For Stylus and Sass you could do this (live example for Sass):

    .aa
      > .bb, &
        > .cc
          width: 10px
    

    I couldn’t find a way to do so in a one-liner for Sass, but for Less/Stylus/Scss you could do also this (live examples for Scss, for Less) :

    .aa { > .bb, & { > .cc {
      width: 10px
    }}}
    

    This is not that pretty also, but still better than nothing 🙂

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

Sidebar

Related Questions

Consider this code : HTML: <div class='a'>a</div> <div class='b'>b</div> <div id='log'></div> CSS: .a, .b
Consider this HTML: <!DOCTYPE html> <html> <head> <title></title> <style type=text/css> div { position: relative;
For the purposes of this question, consider this: <div class=has_transparent_png> <a href=foo.html> <span> <img
I'm parsing JSON that is contained in an HTML element. Consider this markup: <div
This problem is only in IE. Consider the following HTML: <html> <body> <div style='position:absolute;left:1em;right:1em;top:1em;bottom:1em;overflow:auto;>
Please consider this HTML and CSS snippet: #container { border: 1px solid red; height:
Consider this HTML: <ul> <li>first</li> <li>second</li> <li>third</li> </ul> This CSS: li:first-child { background: yellow;
Consider this example: http://jsfiddle.net/treeface/P8JbW/ HTML : <div id=test> <img src=http://ycombinator.com/images/y18.gif /> </div> CSS :
Consider the following piece of code: HTML: <div> <img src=http://placehold.it/600x150 /> </div> CSS: div
Consider the following example : HTML: <div class=wrapper> <div class=left>Some text here</div><div class=right>Hello Stack

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.