Intermediate CSS Flashcards
You can define your own selectors in the form of _______ selectors
class and id
What is the benefit of classes and ids?
The benefit of this is that you can have the same HTML element, but present it (style it) differently depending on its class or id
A class selector is a name preceded by a _______
full stop (“.”)
An ID selector is a name preceded by a ________
hash character (“#”)
What is the difference between an ID and a class?
An ID can be used to identify one element, a class can be used to identify more than one
p.jam { property: value; }
Style only paragraph elements that have the class “jam”.
Two ways you can simplify HTML and CSS
Grouping and Nesting
What is grouping?
You can give the same properties to a number of selectors without having to repeat them. Separate selectors with commas in one line
You can specify properties to selectors within other selectors using _______
Nesting
_________ are bolted on to selectors to specify a state or relation to the selector
Pseudo classes
selector:pseudo_class { property: value; }
a:link {
color: blue;
}
Target unvisited links with a pseudo class and color them blue
a:visited {
color: purple;
}
Target visited links with a pseudo class and color them purple
Commonly used for links, the _________ can be used to apply styles when something happens to something
dynamic pseudo classes
a:active {
color: red;
}
dynamic pseudo class used to target a link activated by the user, and then color it red
a:hover {
color: blue;
}
dynamic pseudo class used to target a link hovered over by the user, and then color it blue
input:focus, textarea:focus {
background: #eee;
}
dynamic pseudo class used to target an input field or textarea that has focus, and then color the background
Target something only if it is the very first descendant of an element
The first-child pseudo class
p:first-child {
font-weight: bold;
font-size: 40px;
}
Style the first paragraph
margin-top: 1px;
margin-right: 5px;
margin-bottom: 10px;
margin-left: 20px;
To shorthand
margin: 1px 5px 10px 20px;
What do these values target?
padding: 1em 10em;
The first value will be the top and bottom
The second value will be the right and left