Mod 4 Flashcards
What is a CSS selector?
A selcetor selects the HTML elements to which the rule applies. This is followed by one or more declarations placed inside a pair of curly braces. Each declaration is a property value pair, specifying a property of the element and then the value we want to set for that property. A colon : separates a property and its value, while different declarations are separated by a semi-colon ;.
h1 {
color: red;
font-size: 25pt;
}
What is a CSS Type Selector?
The type selector matches elements based on the element type, i.e., the tag name. We just saw an example of this which is reproduced below:
h1 {
color: red;
font-size: 25pt;
}
What is a CSS ID Selector?
vvip {
The ID selector selects the single element with a matching ID and is of the form #id.
font-weight: bold; }
What is a CSS Class Selector?
The class selector selects all elements in which the attribute class has that value. The syntax is .class, i.e., we add a . before the value of the class.
Example
The selector .navigation will apply to all elements with the class attribute of navigation.
.navigation {
font-size: 16pt;
}
When should use classes vs. IDs as selectors in our rules?
IDs are good for anchoring and specifying unique blocks, whereas classes are more about design properties that get used again and again.
What are some forms of location based selectors?
Descendant: y x
Child: y>x
Adjacent Sibling: y+x
General Sibling: y~x
What is a CSS Pseudo Selector?
CSS also supports selectors that are based on the state of an element. We can specify pseudo selectors using a selector followed by a pseudo-classLinks to an external site. where a pseudo-class is a keyword preceded by a :. Here is the general syntax:
selector:pseudo-class {
property: value;
}
What are the 3 ways to add style to HTML documents?
- External CSS using separate stylesheet.
- Internal CSS using the style element.
- Inline CSS using the style attribute of an element.
What are 4 general rules for CSS rule precedence?
- Later rules overrule earlier rules.
- Rules with a more specific selector take precedence over those with more general selectors.
- Rules associated with id override rules associated with class
- Rules associated with class override rules associated with tags
What is the ratio between points and inches?
1pt = 1/72 of an inch
What is the ratio between pixels and inches?
1 px = 1/96th of an inch. Many browsers ignore this definition, and instead use pixel size based on the resolution of the screen
What are em and rem in CSS?
- em is a relative unit based on the current font size of the parent element. For example, 2em means two times the parent element’s current font size.
- rem is a relative unit based on the current font size of the root element. For example, 2rem means two times the current font size of the root element.
What is the difference between block-level and inline elements?
Recall that elements such as h1, p, ul, li are block-level elements and start on a new line, whereas elements such as img, b, i are inline elements and do not start a new line.
Describe the 4 size properties in a box model.
- Element.
We can specify width and height properties to override element defaults. - Padding.
We can specify the size of the padding using the properties padding-top, padding-right, padding-bottom and padding-left. - Margin.
We can specify the size of the margin using the properties maring-top, margin-right, margin-bottom and margin-left. - Border.
We can specify the color, style, and width of the border at the top, bottom, left, and right, using 12 different properties.
The names of the properties for controlling the border at the top are border-top-color, border-top-style and border-top-width.
The declaration padding: 10px 20px 30px 40px; specifies the 4 padding sizes in the order top, right, bottom, and left.
What is static positioning?
Static positioning is the default method which uses the browsers default positioning algorithm to stack each block level element on a new line.