CSS Flashcards
What declaration block should you use to add “cursor: pointer” to links when hovering over them?
a {}
Styling the cursor on a:hover {} can cause unwanted behaviors, while styling the cursor in the a {} block will still only modify the cursor when hovering.
What are the four main states of links? What are their associated pseudo-classes?
Bonus: In what order should their CSS rules be written for proper cascading?
Normal (not clicked), hover, active (clicked), and visited.
:link
:visited
:hover
:active
The above order properly cascades the link states.
What are the four layers of the box model?
From innermost to outermost:
- Content
- Padding
- Border
- Margin
What does the text-transform property determine?
Bonus: what are the four main values (including the default)?
The capitalization of text on the screen.
none: default value, no rule imposed
uppercase: text will be all-caps
lowercase: text will be no-caps
capitalize: the first letter of each word will be capitalized
What is the difference between the following selectors?
div p {}
div > p {}
The descendant selector (“div p {}”) will apply rules to any p element which descends from a div element.
The child selector (“div > p{}”) will only apply rules to p elements with a parent element of div.
What is the difference between the following selectors?
div + p {}
div ~ p{}
The adjacent sibling selector (“div + p {}”) will apply rules to any p elements which come immediately after a sibling div element.
The general sibling selector (“div ~ p {}”) will apply rules to any p elements which are at any point preceded by a sibling div element.
In other words: the adjacent sibling selector applies to elements which come directly after a specific sibling, while the general sibling selector applies to elements which come any time after a specific sibling.
What do the following selectors apply rules to?
p::before {}
p::after {}
They style any text inserted with the “content” property in that selector. In this example, text will be inserted immediately before or after p elements.
Example:
p::before {
content: “example text”;
color: red;
}
The above example will insert red text saying “example text” before all p elements. Note that the content property can be a reference, rather than a static string.