CSS Selectors Flashcards
CSS Purpose
mainly to prescribe how the various HTML elements in a set of HTML documents should render, on the screen, on paper, or in other media.
Three different ways in that CSS can be used in HTML documents:
- An external style sheet. A reference inside the element (inside the section)
- An internal style sheet. Defined within the element (inside the section)
- An inline style. added directly to the element (which applies the rules) as an attribute
When multiple CSS styles are defined for the same element,
the value from the last read style sheet will be used.
Styles application priority:
- Inline style
- External and internal style sheets
- The browser default value
CSS rule-set components:
- selector(s)
- declaration block(s)
The declaration block contains one or more declarations separated by semicolons.
Each declaration includes a CSS property name and a
value separated by a colon.
The declaration block contains one or more declarations separated by semicolons.
Each declaration includes a CSS property name and a
value separated by a colon.
CSS selectors are used to find elements in the HTML document based on
element name, ID, class, attribute, or other specifiers.
CSS Selector: Elements div with an attribute class=”even”
div.even
CSS Selector: An element with id=”login”
login
CSS Selector: All elements
*
CSS Selector: All input elements
input
CSS Selector: All p and all div elements
p,div
CSS Selector: All input elements (descendents) inside all div elements
div input
CSS Selector: All input elements that have the div element as the (direct) parent
div > input
CSS Selector: Selects all p elements that are placed immediately after element br
br + p
CSS Selector: Selects all p elements that are placed immediately before element br
p ~ br
XPATH: Elements div with an attribute class=”even”
//div[@class=”even”]
XPATH: An element with id=”login”
//*[@id=”login”]
XPATH: All elements
//*