views:

114

answers:

5

For example I have a CSS selector:

#spotlightPlayer .container .commands.over span,
#spotlightPlayer .container .commands.over ul,
#spotlightPlayer .container .commands.over ul li { clear:both }

Is there a way to write like,

(#spotlightPlayer .container .commands.over) span, ul, ul li { clear:both }
A: 

Sounds like the problem is with your document structure and not your CSS. Do you really need that long a list of identifiers to get the specificity that you need? You should only need attributes on your HTML elements such as it takes to describe the data you're displaying.

Jeremy DeGroot
I need all of them
dynback.com
A: 

If all you want is to clean up your CSS, and you don't care about making your HTML messy, apply a class to each span, ul, and ul>li element in the relevant section. You can clear out two extra lines of CSS, but you'll be gaining a lot of weight in HTML cruft. I wouldn't recommend this.

kyle
simply speaking, there is no such possibility
dynback.com
+2  A: 

You could use some kind of CSS pre-processors like Shaun Inman’s CSS server-side pre-processor to convert this:

#spotlightPlayer .container .commands.over {
    span,
    ul,
    ul li { clear:both }
}

into this:

#spotlightPlayer .container .commands.over span,
#spotlightPlayer .container .commands.over ul,
#spotlightPlayer .container .commands.over ul li { clear:both }

But CSS itself has no such syntax.

Gumbo
+1  A: 
Peter Boughton
Yeah, never heard about such preprocessor things, fantasy on rise - if such thing could handle css hacks for all browsers, like meta css language.
dynback.com
+1  A: 

You might check out Sass. It has a lot of helpful little features that let you make your style sheets more declarative than the normal CSS syntax allows. It handles deeply nested tags in a very natural way. In Sass, this would be:

#spotlightPlayer .container. commands.over
  span, ul, ul li
    :clear both
Chuck
sorry, my brain is not for haml style, i like css-style more
dynback.com
Fair enough. I just thought it was worth mentioning since it does make this problem trivial. Some people love it, some not so much. Different strokes and all.
Chuck