CSS Flashcards
What are the names of the individual pieces of a CSS rule?
A CSS rule contains two parts: a selector and a declaration.
p {
font-family: Arial;}
‘p’ is the selector and ‘font-family: Arial;’ is the declaration.
Selectors indicate which element the rule applies to. The same rule can apply to more than one element if you separate the element names with commas.
Declarations indicate how the elements referred to in the selector should be styled. Declarations are split into two parts (a property and a value), and are separated by a colon.
In CSS, how do you select elements by their < class > attribute?
Matches an element whose class attribute has a value that matches the one specified after
the period (or full stop) symbol.
.note {} = Targets any element whose class attribute has a value of note
p.note {} = Targets only < p > elements whose class attribute has a value of note
In CSS, how do you select elements by their tag name?
Using the type selector. Matching their element name.
h1, h2, h3 {} = Targets the < h1 >, < h2 >, and < h3 > elements.
In CSS, how do you select an element by its < id > attribute?
introduction {} = Targets the element whose id attribute has a value of introduction.
Matches an element whose id attribute has a value that matches the one specified after
the pound or hash symbol.
What are inside of CSS declarations?
CSS declarations sit inside curly brackets and each is made up of two parts: a property and a value, separated by a colon. You can specify several properties in one declaration, each separated by a semi-colon.
h1, h2, h3 {
font-family: Arial;
color: yellow;}
Properties: font-family, color
Values: Arial, yellow
CSS Universal Selector
Applies to all elements in the document. * {} Targets all elements on the page.
CSS Child Selector
Matches an element that is a direct child of another.
li>a {}
Targets any < a > elements that are children of an < /a >< li >< a > element (but not other
< /a >< a > elements in the page) < /a >< /li >
CSS Descendant Selector
Matches an element that is a descendent of another specified element (not just a direct child of that element).
Targets any < a > elements that sit inside a < p > element, even if there are other elements nested between them.
CSS Adjacent Sibling Selector
Matches an element that is the next sibling of another.
h1+p {}
Targets the first < p > element after any < h1 > element (but not
other < p > elements).
CSS General Sibling Selector
Matches an element that is a sibling of another, although it does not have to be the directly preceding element.
h1~p {}
If you had two < p > elements that are siblings of an < /p >< h1 > element, this rule would apply to both.< /h1 >
Name three different types of values you can use to specify colors in CSS.
RGB values (example: rgb(100,100,90))
Hex Codes (example: #ee3e80)
Color Names (example: DarkCyan)
What CSS properties make up the box model?
Content box: The area where your content is displayed; size it using properties like inline-size and block-size or width and height.
Padding box: The padding sits around the content as white space; size it using padding and related properties.
Border box: The border box wraps the content and any padding; size it using border and related properties.
Margin box: The margin is the outermost layer, wrapping the content, padding, and border as whitespace between this box and other elements; size it using margin and related properties.
.box {
width: 350px;
height: 150px;
margin: 10px;
padding: 25px;
border: 5px solid black;
}
Which CSS property pushes boxes away from each other?
Margin property
Which CSS property adds space between a box’s content and its border?
Padding property
What is a pseudo-class?
A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a button’s color when the user’s pointer hovers over it.
What are CSS pseudo-classes useful for?
Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator (:visited, for example), the status of its content (like :checked on certain form elements), or the position of the mouse (like :hover, which lets you know if the mouse is over an element or not).
Name two types of units that can be used to adjust font-size in CSS.
Pixels, percentages, ems
What CSS property controls the font used for the text inside an element?
font-family