Taught by
Alexandra Ackerman
Code available at
https://github.com/newschool-webfundamentals
Presentations available at
newschool-webfundamentals.github.io
Build this webpage.
Last class we discussed structuring the content of webpages with HTML.
This week, we'll go over styling our pages.
Cascading Style Sheets
Describes rules for how HTML elements should be displayed on a screen.
HTML elements sit within invisible boxes
Red outlines are block elements, blue are inline elements.
Block elements look like they display on a new line.
<h1>, <p>, <div>
Inline elements flow within the text and don't start a new line.
<a>, <i>, <b>
CSS creates rules for how different HTML elements (the boxes) are presented
Headers have a black background and white Helvetica fontThere are many different styles you can control in these boxes:
CSS rules contain two parts - a selector and a declaration
Selectors describe the element that the style rule should apply to.
Declarations refer to how the selector element should be styled.
Declarations have two parts: a property and a valueProperties describe what aspect of the element should be styled, and values describe how.
There are three ways to write CSS rules into a page.
In-line style are written by adding a style attribute to each element
Style tags in the head describe style across the whole page
Stylesheets are their own files and can be included in any html file.
In the class, you should keep all CSS in stylesheets. Why do you think developers prefer this?
Let's talk about a few ways you can select an element for styling
We already went over type selectors. We did this when we specified the type of tags that we want to style
Class selectors match elements with a class attribute that have the same value
ID selectors match elements with an ID attribute that have the same value
Stylesheets display based on specificity - IDs are more specific than classes
Classes are categories, ids are exact
Why are they called cascading stylesheets?
If two selectors are identical, rule displayed last has the most importance.
Margin is the space between the element's border and other elements. Padding is the space between the content and the element's border.
Here's a closer look
Let's build a site together!
Now that you've seen me do it, begin adding style to your portfolio / main project. Consider styling a: