-2

I'm having trouble using some relatively simple CSS selectors using :not. Namely, the following selector is giving me an error:

a:not(.ebook_document *)

I am trying to get all <a> elements that are not children of the element with class ebook_document. This also fails:

a:not(.ebook_document > *)

As well as this:

a:not(.ebook_document, *)

Putting the selectors on their own, not in a :not section works fine. What have I done wrong?

markasoftware
  • 12,292
  • 8
  • 41
  • 69
  • 2
    :not only takes a _simple_ selector. Plus, https://developer.mozilla.org/en/docs/Web/CSS/:not - _"This selector only applies to one element; you cannot use it to exclude all ancestors. For instance, `body :not(table) a` will still apply to links inside of a table, since will match with the :not() part of the selector."_ What you want is not possible using :not. – CBroe Oct 29 '16 at 03:24
  • @CBroe ok, that answers my question. Thank you. – markasoftware Oct 29 '16 at 03:25

2 Answers2

3

:not only takes a simple selector. (For now, CSS 4 expands that to a selector list.)

Plus, https://developer.mozilla.org/en/docs/Web/CSS/:not -

This selector only applies to one element; you cannot use it to exclude all ancestors. For instance, body :not(table) a will still apply to links inside of a table, since will match with the :not() part of the selector."

What you want is not possible using :not.

You can only go about it the other way around - format all "normal" links, and then apply different formatting for the links inside the target element(s) using .ebook_document a { ... }

So that means rather than not applying styles to those links in the first place, you might need to overwrite the styles you don't like for those links again.

(Or use initial/all to actually reset styles, but browser support for that is still lacking AFAIK.)

Community
  • 1
  • 1
CBroe
  • 91,630
  • 14
  • 92
  • 150
0

Hmm shouldn't it just be a:not(.ebook_document)? I didn't test it but it seems that that should reference all the a tags that don't have a .ebook_document tag.

Jleibham
  • 480
  • 2
  • 9
  • 26
  • I want all a tags that are not a child of a .ebook_document, even if they do not have a .ebook_document class on them theirself. – markasoftware Oct 29 '16 at 03:24