0

How would you force and element to gain priority in CSS?

For e.g. .apple.pear {} p.apple {} .apple p {} Does this exist? .apple, .orange, .pear {} or .apple .orange .pear wich is the decent selector

13th Jun 2017, 7:53 PM
SauceCode
SauceCode - avatar
2 odpowiedzi
+ 3
> Comma (,) is used to set many selectors for same rules: it doesn't modify the priority of each selector, as they aren't combined... > Priority of selectors is computed based on the number of identifier used and on their type. > Space ( ) is used to select inside childs of left side: 'div p' will select all <p> childs (direct or not) of a <div> element. In same way '#myid .myclass' will select all element having the class 'myclass' and descendant of the element with id 'myid'. > No space is used to combine differents identifier types and/or many class names: 'div#myid.myclass1.myclass2' is certainly overqualified, but will get more priority than '#myid' or even 'div#myid'... and will target (if it exist) a <div> element with id 'myid' and at least classes 'myclass1' and 'myclass2'. > Angular right brackets (>) select direct childs (as space, but only in direct childs, not in deeper descendants ) > Plus (+) select direct sibling... There are a lot of operator and pseudo-selector to target very accuratly any element of an html document ;)
14th Jun 2017, 1:17 AM
visph
visph - avatar
+ 15
All these exist...
13th Jun 2017, 7:54 PM
Valen.H. ~
Valen.H. ~ - avatar