CSS Flashcards
What is the basic syntax of CSS made up of?
A selector, property and value
What does a basic css syntax look like?
An example.
div.bold-text {
font-weight: 700;
}
Label the parts of a syntax. Selector.
div.bold-text {
font-weight: 700;
}
(div.bold-text)
Label the parts of a syntax. Property.
div.bold-text {
font-weight: 700;
}
(font-weight:)
Label the parts of a syntax. Value.
div.bold-text {
font-weight: 700;
}
(700;)
What are selectors?
HTML elements to which CSS rules apply.
What are universal selectors? What’s their syntax?
The universal selectors will select elements of any type and the syntax for it is a simple asterisk
- {
color: purple;
}
What are type (element) selectors? syntax?
A type or element selectors will select all element of the given element type, and the syntax is just the name of he element.
div {
color: white;
}
What are class selectors?
Class selectors will select all elements with a given class
What does a class attribute look like and what are their functions?
[<div (class=“name”)> …]
Just an attribute, like a tag you put on an HTML element.
Rules and features of a class attribute?
You can add as many class as you want to an element using spaces.
They aren’t required to be unique.
What does a class selector syntax look like?
.alert-text {
color: red;
}
What are ID selectors?
They select an element with a given ID
What is an ID attribute? What does it look like?
An attribute you place on an HTML element.
[ <div id=“title”> … ] I
What do ID selectors look like?
title {
background-color: red; }
Rules for ID attributes and selectors
Case sensitive
Only use when necessary
ID’s are unique and cannot be repeated
Should not contain whitespaces
How to group selectors?
Group them in a comma separated list, if they share declarations.
.read,
.unread {
color: white;
background-color: black;
}
How to chain selectors?
If you want to add a style separately to an element that contains both classes or ids.
.subsection.header {
color: red;
}
.subsection#preview {
color: blue;
}
chain selectors rules
You can’t chain more than one type selector.
What are descendant combinator?
Allows us to combine multiple selectors with parent child relationships
How does a descendant combinator look like?
A single space between selectors.
.ancestor .contents {
/* declarations */
}
Rules for descendant combinator
You can add as many as you want .
Avoid elements that need a large amount of nesting, can get complicated.
Function of the color property?
Sets an element’s text color
Function of background-color property?
Sets the background color of an element.