2

Possible Duplicate:
What’s the difference in the :not() selector between jQuery and CSS?

How to write CSS selector for a class 'ui-content'. But it should not be child of a id 'ui-container'?

I tried with following selector in CSS.

.ui-content:not(#ui-container > .ui-content) {
    //styles goes here
}

But it does work in jquery like $('.ui-content:not(#ui-container > .ui-content)'), but not in pure CSS.

How to correct this CSS selector?

Does all selectors working with jquery doesn't work with pure CSS selectors?

Community
  • 1
  • 1
Justin John
  • 8,667
  • 14
  • 67
  • 126

2 Answers2

2

This is simple:

:not(#ui-container) > .ui-content{
   // style
 }

You just need to make sure that there are no other classes that can comply to not being #ui-container and still be .ui-content's direct parent.

Rodik
  • 3,994
  • 24
  • 47
0

You cannot use logic like this in CSS if you want to support IE8 or lower as you are essentially going up the DOM to look at a parent element which CSS cannot do.

The alternative is to apply a global style to all .ui-content elements, and then use a more specific selector to override that style for elements inside the container, eg #ui-container .ui-content. Try this:

.ui-content {
    color: #C00;    /* Dark red */
}

#ui-container .ui-content {
    color: #CCC;    /* Grey */
}
Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318