Unit 3.2 CSS Flashcards
Attribute selectors come in handy for styling:
Forms
Define “attribute selector”
The CSS “attribute selector” matches elements based on the presence or value of a given attribute
DRY CSS stands for:
Don’t Repeat Yourself
”>” combinator:
targets a direct child of an element
”+” combinator:
targets an element’s immediate(adjacent) sibling
”~” combinator:
targets all the specified siblings that follow an element
“:first-child” :
represents the first element among a group of sibling elements
“:last-child” :
represents the last element in a group of sibling elements
Define “pseudo” classes
a keyword added to a selector that specifies a special state of the selected element(s)
“:only-child” :
represents an element without any siblings. So targets elements with a single child.
“:empty” :
represents any element that has no children.
”^” : and write example
“begins with” tells the browser to match a piece of code that’s at the beginning of an attribute’s value.
”$” : and write example
“ends with” tells the browser to match a piece of code that’s at the end of attribute’s value.
“*” : and write example
“contains” tells the browser to matcha piece of code that can be any part of an attribute’s value
When do we want to use these types of selectors? (child, attribute, combinators)
- When a CMS or framework allows no access to HTML
- When we are unable to add classes or IDs to elements
- With dynamic lists or image galleries
“:checked” :
pseudo-class selector represents any radio (), checkbox (), or option ( in a ) element that is checked or toggled to an on state.
“:disabled” :
pseudo-class represents any disabled element. An element is disabled if it can’t be activated (selected, clicked on, typed into, etc.) or accept focus.
Define “:nth-child()” pseudo-class
the “nth-child” matches elements based on their position among a group of siblings
With “:nth-child()” how can we target a list of elements starting with the 3rd sibling then every other item from that element?
Using the argument (2n+3)
What arguments can we pass to “:nth-child()” to target either all odd siblings or all even siblings
(even) or (odd)
“:nth-of-type” :
pseudo-class targets an element based on its position within a parent, but only if it’s a specific type of element.
“:nth-last-of-type” :
pseudo-class targets the last to first element based on its position within a parent, but only if it’s a specific type of element.
“:root” :
matches the root element of a tree representing the document. In HTML :root represents the element
“:target” :
CSS pseudo-class represents a unique element (the target element) with an id matching the URL’s fragment.
“:not()” :
pseudo-class is referred to as a negation pseudo-class because it selects everything except the element we specify in the selector.
”::first-line and ::first-letter”
pseudo-elements let us target the first line of text and the first character in a line of text.
”::before and ::after pseudo-elements” :
let us insert virtual elements before and after an element’s content. These virtual elements are visible to the user and are style-able with CSS, but they do not appear in the source code.
The only way we’re able to generate pseudo-elements
is with the “content” property (even if it’s empty)
Pseudo-elements do NOT work with
images and form elements