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.
What do color properties accept?
A keyword like red
The transparent keyword
HEX, RGB, and HSL
Function of the font-family property?
Determines what font an element uses.
What does the value of the font-family property look like?
Single value or comma separated list of values that determine what font an element use.
Why do some values of the font-family property have double quotes?
A font family name like “DejaVu Sans” which uses double quotes because of space brown the word
A generic family name like sans-serif
which never used quotes cus no space,
Why add a list of fonts?
For when a browser doesn’t support one it keeps on going down till it finds the one it supports.
Function of the font-size property?
Set the size of the font
How does the font-size property value look like? Rules?
font-size: 22px
No spaces in the values
Function of the font-weight property?
Affects the boldness of the text
font-weight property values. Rules.
The value can be a keyword.
font-weight: bold
Or a number between 1-1000
font-weight: 700 (=bold)
Usually the increment is of 100 up to 900. Depends on the font.