- What CSS is
- CSS syntax
- Element, class and ID selectors
- Formatting text
- The box model
- Put it all together
- CSS controls presentation of HTML
- Constantly changing standards
- Varying Support Across browsers
- All browsers apply basic styling to HTML:
- Margin, Padding, Font size, Underlining links etc
- Browsers apply their own default styles
- Each rule targets a specific tag or element on a HTML document
- Rule which targets all 'p' tags on a page
- Rule which targets all tags with an #id
- Rule which targets all 'a' tags in the #nav
All CSS rules are made of two components:
SELECTOR DECLARATION
#page-header
{font-size: 10px;}
Selectors can target tag names, ID's, classes and many other things
#header p {declaration}
.comment div {declaration}
li {declaration}
Declarations contain properties and values
#selector {font-size: 10px;}
#selector {
font-size: 10px;
color: red;
}
- Inline styling - YUK
- Embedded style sheets - YUK
- External style sheets - Cowabunga
- Time consuming to style multiple elements
- Tricky to manage and update
- Messy
- Goof for very specialised rules
- Time consuming to apply global styles
- Hard to maintain and update
- Good for making specific page styles
- Inline styling
- Embedded style sheets
- External style sheets
/* Comments */
h1 {
font-size: 32px;
}
div {
width: 100%;
background-color: grey;
}
Both are a way to describe your content
- Classes can be used multiple times on a page
- IDs can be used only once per page - they are unique!
p { color: black;}
p { color: red;} - This rule wins
#main-content p { color: black;} - This rule wins
p { color: red;}
ID's 100 point Classes 10 point Elements 1 point