2

Is there a way to create a css group inside of a css selector.

Eg:

.SectionHeader
{
    include: .foo;
    include: .bar;
    include: .baz .theta .gamma .alpha .omega .pi .phi;
}

Trying to see if there is a way to do this at the CSS level instead of inside of a class=".foo .bar .baz .theta .gamma .alpha .omega .pi .phi" tag. I have to use the combination of classes in a few places and want to avoid all that cut and paste.

2 Answers 2

4

No, you can't do this in pure CSS as things stand.

There are some moves afoot to extend CSS to allow things like this, but it's very early days Google has some demonstrated some extended syntax working in a dev version of Chrome, but it'll be a while before it goes live, and even longer before it has sufficient cross-browser support to be actually useful.

In the meanwhile though, there are a number of CSS extension products available which allow you to write stylesheets with nested rules, etc. You would then need to run your stylesheets through a parser to convert them into "real" CSS before you put them on your site, but it might be a compromise you're prepared to make.

If so, check out SASS and Less, among others.

[EDIT] By the way, I mentioned that Google have been demonstrating some extended CSS syntax. Here's a link to a blog post about it: http://www.xanthir.com/blog/b49w0

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the push in the right direction. Both libraries look great, and have been doing lots of reading on which to roll with. SASS is winning as of now, mainly due to its integration with Compass and wider adoption overall. If you ask me though, I think that the components of SASS should be the default implementation of CSS to begin with.
@MindWire - as I said, Google is pushing to have some of these features standardised into CSS, and with their current speed of development I'd say you should expect to see some of it appearing in Chrome within a year. But it'll be a long time before it's in enough browsers to be considered usable. I'll edit the answer to link to a relevant article.
See the relevant section of the proposed CSS3 draft: dev.w3.org/csswg/css3-hierarchies This is not part of CSS; it is currently a proposal.
1

No, but as you stated you can assign multiple classes to an element:

<div class="SectionHeader foo bar"></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.