css selectors - CSS select multiple descendants of another element -
is possible select multiple elements have ancestor of class, id, etc in css? e.g:
table.exams caption, tbody, tfoot, thead, tr, th, td
if not, there way select descendants of element?
is possible select multiple elements have ancestor of class, id, etc in css?
currently, not without duplicating entire ancestor selector , specifying of descendants, unfortunately1:
table.exams caption, table.exams tbody, table.exams tfoot, table.exams thead, table.exams tr, table.exams th, table.exams td
it until late after selectors 3 being finalized proposed pseudo-class notation this, , basic implementations have started showing up. see this answer little history lesson.
in short, pseudo-class that's entered standard known :matches()
. in distant future, once browsers start implementing :matches()
, able this:
table.exams :matches(caption, tbody, tfoot, thead, tr, th, td)
if not, there way select descendants of class?
well, can use asterisk *
, represents any element. given have th
, td
in selector, mean descendants rather children of table.exams
, don't use >
, use space instead:
table.exams *
but really, avoid doing this. if can, utmost specify kind of descendants you're trying select.
1 specifically tables, can away table.exams > :not(.colgroup), table.exams > * > tr > *
, can tell incredibly cryptic (not mention assumes have no script-supporting elements or nested tables within table) , you're better off listing descendants want explicitly.
Comments
Post a Comment