0

If I have the following selector:

#doctors h2 {
    /* CSS CODE HERE */
}

Is this selector pointing to all <h2> element that are descendants of elements with id="doctor"

Vishwa Iyer
  • 841
  • 5
  • 14
  • 33
  • Aside from the fact that it'd be `id="doctors"` and not `id="doctor"`, that seems fine. (Note that there should only be one element with an id of "doctors" though...it's an id.) Is there a particular difficulty you're having with this? – Serlite Jan 18 '17 at 21:29
  • 2
    Yes, it is. please note that this includes _ANY_ `

    ` within the `#doctors` element, even if they are a descendant of a descendant of a descendant of a ...

    – Jhecht Jan 18 '17 at 21:29
  • Yes that is the selector to modify all h2 elements contained in the doctors element. – Kyle Jan 18 '17 at 21:29
  • It can't be elements with `#doctors` it can only be one element. – Nenad Vracar Jan 18 '17 at 21:30
  • What would happen is there is more than one element with `id="doctors"` or is this not possible in HTML? – Vishwa Iyer Jan 18 '17 at 21:34
  • @VishwaIyer For that concern, consider reviewing [Several elements with the same ID responding to one CSS ID selector](http://stackoverflow.com/questions/7262195/several-elements-with-the-same-id-responding-to-one-css-id-selector). It works...in some use cases. – Serlite Jan 18 '17 at 21:38
  • You should not use ids for CSS selectors at all. That's true even more so for selectors that have non-id selectors depend on id context (like in this example). – connexo Jan 18 '17 at 21:49

1 Answers1

1

Exactly. #doctors h2 selects all <h2> elements which are descendants of the element with id="doctors".

Jacob
  • 2,212
  • 1
  • 12
  • 18
Wais Kamal
  • 5,858
  • 2
  • 17
  • 36