##Today's Project
Follow [this link](project/final.html) to see the whole project!

##A demonstration of what can be
##accomplished through CSS-based design

http://csszengarden.com/
##Setting Up Our Dev Tools
**[Sublime Text](http://www.sublimetext.com)** - a text editor with colour highlighting and other helpful features. If you are unable to install Sublime Text, try installing: [Notepad++](http://notepad-plus-plus.org/) (Windows) or [Atom](https://atom.io/) (Mac).
**[Google Chrome](https://www.google.com/intl/en-CA/chrome/browser/)** - Choose a modern web browser that supports current web standards and has good development tools. To set Chrome as your default browser, follow [these instructions](https://support.google.com/chrome/answer/95417?hl=en). Another good option is Firefox. Visit [browsehappy.com](http://browsehappy.com) for more info about modern browsers.
**Developer tools** allow us to *inspect* any web page to see how it's built. These tools also make it easier to test and debug code. The tools can be accessed in 3 ways:
* right-click / two-finger tap on a web page and select **Inspect Element**
* select the menu icon in the top right hand corner of the Chrome browser and select **Tools > Developer Tools**
* keyboard shortcut: **Ctrl + Shift + I** (PC) / **Cmnd + Option + I** (Mac)
##Setting Up Our Work Flow
Inside of the folder you downloaded today, **llc-css-fundamentals-master**, there are many more folders and files that contain different content.
```
llc-css-fundamentals-master
|-- framework // Contains files needed for slide presentation. Do not edit!
|-- project // Contains files for today's workshop.
|-- css // Only CSS files here.
|-- examples // Example HTML & CSS files for each exercise.
|-- images // Images for your project. You can also add your images here.
|-- final.html // Finished example for reference. The CSS file is in the CSS folder.
|-- index.html // Your resume HTML page.
|-- index.html // This is the file you're viewing right now (slides)!
```
##Setting Up Our Work Flow
Open our project files in the browser and text editor.
1. Open Sublime Text and go to **File > Open**.

1. Navigate to the **Project** folder (in the folder you downloaded with today's slides). With the entire folder selected, select **Open**.
1. The folder will appear in Sublime's side bar. Double click on **index.html** in the sidebar to open it.
1. Right click or two finger tap and select **Open in Browser**. This will open the HTML file in your *default* browser.

No CSS has been applied yet so all you will see is the HTML content and the default styles like in [this example](project/examples/1-no-css.html).
#hypertext markup language
##The content layer
#Before we continue...
##...let's have a quick show of hands
##HTML: Quick Review
HTML is used to define *content* and HTML tags are used to describe the meaning of your content.
**Title**: Found in the `<head>` section of the HTML document. Used for defining the page title. Displays in the browser's tab, search engine results and bookmarks.
```xml
<title>Page Title</title>
```
**Headings**: There are 6 heading tags available (`<h1>,<h2>,...,<h6>`) and follow a hierarchical structure. `<h1>` represents the most important title/heading on the page and it's best to stick to using it just once per page. Other headings can be used multiple times. It's important to use the appropriate tag to describe the content, not for the default heading styles. That's what CSS is for!
```xml
<h1>Most Important Heading</h1>
<h2>Important But Not As Much As h1</h2>
```
**Paragraphs**: Created with the `<p></p>` tags.
```xml
<p>I'm a paragraph.</p>
```
**Link**: requires the addition of an `href` *attribute* to specify where to link to.
```
<a href="http://website.com">link</a>
```
**Lists**: There are two kinds of lists: ordered (`ol`) for numbered lists & undordered (`ul`) for lists with bullets. Content must be included only within the list item (`li`).
```xml
<ul>
<li>Unordered list item</li>
<li>Unordered list item</li>
</ul>
<ol>
<li>Ordered list item</li>
<li>Ordered list item</li>
</ol>
```
**Images**: like links, also requires the an additional attribute, `src`, for linking to the image file.
```
<img src="path/to/image.jpg">
```
Exercise #1: Personalize the content (5-10 mins)
- Update the page title in the
title
tag.
- Update your name and tagline in the
header
section.
- Update your profile image.
Bonus: If you have some extra time, try updating the content for the rest of the page.
Don’t forget to save your changes (File > Save) and refresh the browser after each update! Don’t worry if you don’t finish. There’s placeholder content already included in the starter template.
Protip! Improve your work flow with keyboard shortcuts:
CMD/CTRL + S to save
CMD/CTRL + R to refresh the browser
Give the class 5 mins and then check if they completed #1-3. If not give them 5 more minutes.
#Cascading Style Sheets
##The presentation layer
##CSS Overview
HTML defines *content*, CSS defines the *presentation*.
**Selectors:** used to determine which element(s) to apply the styles to. Can target an HTML tag, class or ID attribute (more on these later).
**Declaration block:** consists of a list of declarations (rules to follow) wrapped in curly braces `{}`.
**Declarations** or rules to follow, are written using `property:value` pairs.
```css
selector {
property: value;
}
```
**Properties** determine the type of style to be applied to
the element (e.g. color).
**Values** are specific to the property. Declarations must end with a semi-colon (`;`) to indicate that the instruction is complete.

##Comments
Comments in CSS are written between a slash & asterisk and must close in the opposite order. Comments are great for ... well... leaving comments! Leave notes for yourself (or others), organize your code blocks or for "commenting" out your code (hiding it for later).
```
p {
color: #cc0066; /* magenta */
}
/* HEADER STYLES */
header {
width: 80%;
}
/* Saving this for later
.slider {
width: 100px;
background: red;
}
*/
```
##Class & ID attributes
When **type selectors** are too general (targeting the HTML element), HTML gives us two ways to attach extra identifying information to target specific elements with two **attributes**, `class` (can be used multiple times) and `id` (can only be used once per page).
```
/* targets ALL parapraphs */
p {
color: blue;
}
/* only applies to the element that contains this class, defined by leading period */
.danger {
color: red;
}
/* only applies to the element that contains this id, defined by number symbol */
#danger {
border: 1px solid red;
}
```
```xml
<p>Regular text.</p>
<p class="danger">Red error message text or some other dangerous text.</p>
<div id="danger">Will display a red border.</div>
```
##class & id Naming Conventions
When choosing a `class` or `id` name, use a descriptive name and do **not** use spaces. Hyphens (-), underscores (_) and camel case are acceptable.
CSS is also case sensitive, so while these three examples look similar, CSS will read these as three different classes so it's important (for your own sanity) to pick one style and be consistent.
```
class="content-wrapper"
class="content_wrapper"
class="contentWrapper"
```
##CSS color Values
**keywords** - use the actual name for most basic colours (red, green, blue, pink, etc) as well as a few fancy ones like "papayaWhip" and "paleGoldenrod".
**RGB (red-green-blue)** - Uses *three* numerical values from 0-255. 0 represents black, 255 represents white. See below for syntax.
**hex code** - Made up of the number sign (`#`) followed by six hexadecimal characters (0-9, A-F).
```
/* These are all the same colour */
p {
background: firebrick;
background: #B22222;
background: rgb(178,34,34);
}
```
**Colour Resources:**
[http://www.colorpicker.com/](http://www.colorpicker.com/)
[http://colours.neilorangepeel.com/](http://colours.neilorangepeel.com/)
[http://www.colourlovers.com/](http://www.colourlovers.com/)
[http://flatuicolors.com/](http://flatuicolors.com/)
[http://color.hailpixel.com/](http://color.hailpixel.com/)
[http://wesandersonpalettes.tumblr.com/](http://wesandersonpalettes.tumblr.com/)
Adding Background Colours
Using the background
property to add colours to various page sections can be very useful when laying out the CSS for your HTML document. We will be going more in depth with the various background options but for now, try changing the colours below and see what happens!
Change my background colour!
##Referencing CSS
There are three ways to include (otherwise known as *referencing*) CSS in an HTML page.
###Inline
Can be used in any HTML element using the `style` *attribute*.
```
<p style="color: blue;">I'm writing CSS!</p>
```
This technique should be avoided but it's good to know how it works in case you encounter it.
###Internal
Uses `<style>` and is included in the `<head>` element.
```
<head>
<title>Page Title</title>
<meta charset="utf-8">
<style>
h1 {
font-size: 16px;
}
</style>
</head>
<body>
<p>I'm still writing CSS!</p>
</body>
```
This method is preferred over *inline* css, however it is still inefficient because if you had multiple web pages, you would have to copy the style block to every single page to duplicate the styles.
###External
Links to a separate style sheet file. This method is recommended because it separates the CSS from the HTML document. The link to the stylesheet is referenced in the `<head>` on any page where these styles need to be included. Only the CSS file needs to be updated rather than the CSS block on every single page.
Referenced in the head element with a `<link>` tag and two **attributes**, `rel` and `href`. Just like creating links, the value of the `href` points to the location of the stylesheet.
Though it is not required, css files are often saved in a css folder for organization, so make sure the file path points to the appropriate directory.
The `rel` attribute describes the relationship.
```
<head>
<title>Page Title</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
</head>
```
**Protip!** Sublime Text shortcut: type "link" + tab key. Ta da!
##Exercise #2: add background colours (10mins)
1. In Sublime, open **style.css** (it should be blank) located in **project > css **. Link it (reference it) in your HTML document.
1. Using `background`, add a different colour to each major section of the page. Use an **element selector** for the header and **class selectors** for the sections. Since there are multiple `<section>` tags, we need to use a more specific selector. Here are the selectors to get you started:
```
header { }
.profile { }
.work-experience { }
.skills { }
.education { }
.contact { }
```
**Bonus**: Add comments to organize your CSS into sections to group related CSS together.
Your page should look something like this: [background example](project/examples/2-bg-colours.html) and your CSS will look [similar to this](project/examples/2-bg-colours.css).
All example files can be found under **project > examples**.
Default styles: Reset vs Normalize
You may notice that the colours don't span all the way to the edge of the page. That's because browsers have their own user agent style sheet to add default styles to the html elements. Here's an example of Chrome's user agent style sheet, which can be seen using dev tools:
A CSS Reset is a set of CSS rules that resets the user agent styles of the HTML elements to a consistent, unstyled baseline to avoid cross-browser differences as much as possible.
Normalize is slightly different because it "normalizes" the consistencies to a default style rather than removing the styles. Another option is to choose a reset and customize it yourself to create your own.
Note that if you add it as a separate style sheet, it should be included before your custom style sheet.
These various style sheets can be downloaded at cssreset.com but for today, it’s already included in the project > css folder. Let's add it to today's project file (index.html).
Add the normalize file and discuss the differences and explain why normalize has to come before custom css.
##CSS
Be careful of the order you make CSS declarations! Your text editor isn't going to stop you from doing something like the example below:
```
h1 {
color: black;
}
h1 {
color: blue;
}
```
What colour will the `<h1>` be?
##Cascading Style Sheets
CSS executes from top to bottom (hence *cascading*), so be careful of the the order of your CSS declarations. The declaration that comes *after* will override the one that came before.
```
h1 {
color: black;
}
h1 {
color: blue;
}
```
`<h1>` tags will be blue!
##Cascading Style Sheets
Why is overwriting declarations like this useful?
```
h1 {
color: black;
}
h1 {
color: blue;
}
```
Hint: Can multiple declarations affect the same HTML element?
##Inheritance and Specificity
One of the strengths of CSS is styles can be inherited from parent to child elements using the family tree relationship between the elements.
```
<body>
<h1>My Website</h1><!-- child of body -->
<p>This is a paragraph.</p><!-- sibling of h1 -->
</body>
```
```
body {
color: blue;
font-family: Helvetica, Arial, sans-serif;
}
h1 {
color: black;
}
```
In the above example, the CSS properties in the body selector is inherited by the children and descendants so all the text would be blue and display the Helvetica font. However, when a more specific selector is used (`h1`), it overrides the inherited values because it's more *specific*.
##Web safe fonts
The default font can be changed with the `font-family` **property**. However, not all fonts are installed on all computers so it's recommended to use fonts that are considered *web safe* — fonts that are commonly included on most computers.
It's best practice to list at least two or three font options to provide a fall-back if the user doesn't have the preferred fonts installed.
```
font-family: Helvetica, Arial, sans-serif;
```
Here's a handy resource for referencing web safe fonts: [CSS Font Stack](http://cssfontstack.com/).
Font Styles & Typography
Let's experiment with a few CSS properties for styling text. Try changing some of the values below.
Just some text to test out the above styles. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni repellat sunt quae fugit illum in aut sed, quis nesciunt totam veritatis, dolores alias modi fuga commodi dicta facilis, consequatur temporibus.
Resources:
Text CSS properties reference
http://csstypeset.com- CSS generator
Explain what each property does while updating each example in the code editor.
Class Exercise: Typography
Let's add some styles together using a few web safe fonts, cssfontstack.com.
1. Set the main font-family & line-height using body
as the selector.
body {
font-family: Georgia, Times, "Times New Roman", serif;
line-height: 1.5;
}
2. Set font styles for h1, h2 and h3
h1 {
font-family: "Brush Script MT", cursive;
font-weight: 400;
font-size: 80px;
}
h2 {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
text-transform: uppercase;
font-size: 32px;
}
h3 {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
text-transform: uppercase;
}
- Add main font family & line-height to body - explain inheritance
- put h2, h3 styles into separate blocks to show how to combine selectors to demonstrate refactoring in the next slide. Use this to also explain specificity. Tell learners they have the option to type along or just watch to keep from slowing down the demo. They can catch up in the exercise work session since the final code will be posted in the next couple slides.
##Refactor!
What is refactoring? Code refactoring is the process of restructuring existing code to make it more efficient. Writing clean, organized and efficient code will not only make your pages run faster but will make it easier to maintain and can potentially reduce browser bugs. It's tempting to say "I'll fix it later" but later doesn't always come. It's important to refactor your code as you go along.
If you find you are declaring the same styles over and over again, try applying the style to a parent selector so the styles can be inherited. You can also *combine* selectors to apply the same styles to multiple selectors at the same time. Make sure to separate selectors with a comma.
```
h1, h2 {
/* will apply any styles here to both headings */
}
```
##Class Exercise: Typography (continued)
The previous example can be refactored to look like this:
```
h1, h2, h3 {
font-weight: 400;
}
h2, h3 {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-transform: uppercase;
}
h1 {
font-family: "Brush Script MT", cursive;
font-size: 80px;
}
h2 {
font-size: 32px;
}
```
##Web fonts
For more options than web safe fonts, services like [Google Fonts](http://www.google.com/fonts/) and [Font Squirrel](http://www.fontsquirrel.com/) make it easier to use a variety of fonts without worrying about whether it's installed on the users' computer.
A service like **Font Squirrel** requires you to download the fonts and add it to your project files. The site features a handy [generator](http://www.fontsquirrel.com/tools/webfont-generator) to create different font files to support various browsers as well as include demo files and instructions on how to use it.
**Google Fonts** allows you to link directly to their stylesheet and no file downloads are necessary. To use these fonts:
* Select the fonts you want to use and **Add to Collection**.
* You can **Review** them to take a closer look, then choose *Use* when ready.
* Select font weights. The more you choose, the more it will slow down page load time.
* The default character set should contain what you need. Only select an option if you need to add additional language support.
* Grab the `<link>` code snippet and add it the `<head>` part of your page.
* Use the new fonts with the `font-family` property as listed in the example on the Google Fonts page.
That's it!
Exercise #3: Typography (10mins)
- Find and add 2-3 font families from Google Fonts
- Update the font & typography styles to your liking! You can add some more later as the page starts to come together.
Text CSS properties reference
http://csstypeset.com - CSS generator
Need help deciding on fonts? The example project uses Open Sans (sans-serif), Merriweather (serif), Pacifico (cursive).
Your page should look something like this: Example 3.
Tell learners to take 5 mins to pick fonts. If they can't decide, just use the suggestions provided. Picking fonts is often a long process and this will keep from slowing down the day.
##What is The Box Model?
The browser looks at every HTML element on the page as a rectangular box. The CSS Box Model describes the way CSS styles the size and spacing of HTML elements. Understanding the box model is crucial for understanding how to position elements with CSS to create the desired page layout. This is one of the trickiest part of CSS, so don't worry if it seems confusing!
CSS uses 5 properties to determine the size and spacing of these boxes:
* `margin` - adds/removes space *outside* of the element
* `padding` - adds/removes space *inside* of the element
* `border` - adds a border outside of the element
* `width` - can be set to a specific size via CSS
* `height` - can be set to a specific size via CSS
##Box Model Review
Let’s look at a diagram to see how all these different properties work together to change the size of an element.

The original element started with a width and height of **400 x 100**. After including the padding, border & margin, the size of the box is actually **452 x 152**!
Margin doesn't add to the actual size of the element but should be considered as part of the total size of the element because it adds space *around* it.
Padding and Margin
The padding
and margin
can both be declared using similar syntax of 1 to 4 values. Values can be declared using different measurement units but pixels or percentages are most commonly used. Setting the value to "0" will remove any default space on an HTML element. Any positive value will add space.
- 4 values means top, right, bottom, left
- 3 values means top, right & left, bottom
- 2 values means top & bottom, right & left
- 1 value means the same amount of padding on all sides
Change some values to see the difference between margin and padding. Trying using 1 - 4 values. Let's also inspect the element using Chrome's Developer tool.
padding and margin test
##Padding and Margin (continued)
The previous slide uses the shorthand properties. Both can also be declared by specifying a particular side.
```
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
```
```
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
margin-left: 10px;
```
##Border
The `border` property resides between the `margin` and `padding` and creates an outline around the element. It, too, has longhand and shorthand syntax.
```
/* longhand */
border-width: 2px;
border-style: solid;
border-color: red;
/* shorthand */
border: 2px solid red;
```
Like padding and margin, a specific side of the element can be specified.
```
/* longhand */
border-top-width: 2px;
border-top-style: solid;
border-top-color: red;
/* shorthand */
border-top: 2px solid red;
```
##I Can't... even...

##Box Model Fix!
Luckily, there’s a fix for this. Enter the [box-sizing: border-box](http://www.paulirish.com/2012/box-sizing-border-box-ftw/) fix ftw!
It is recommended to add this snippet to all your projects.
```
/* apply a natural box layout model to all elements, but allowing components to change */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
```

Center aligning with margin
The margin property can also be used to center align block level elements. (More about block level elements later). First, a width needs to be set. Then, setting the left & right values to auto
will find the center of the page. The 0
just refers to the top and bottom value.
box
Margin also accepts negative values. See more here.
Class exercise
- Add the box model fix to our CSS file. link
- Go back to our HTML & CSS project files, add
padding:1px
to the header
section to see how it changes the spacing. Open up the Chrome Dev Tools and inspect the element.
- The content is also too wide. Let’s use the
margin: 0 auto
trick to center align the content. Try adding the styles to the .profile
section in your CSS file.
.profile {
width: 1000px;
margin: 0 auto;
}
Your page will look something like this:

This exercise is to demonstrate why we need to add a wrapper around the content which is covered in the next step.
##Class exercise (continued)
The content is centered but the background colour is restricted by the width dimension and doesn’t span the rest of the page anymore. To fix this, we’ll need to create a “container” just for center aligning the content by adding a new `div` with a class of `content-wrap` *around all of the profile content*.
```
<section class="profile">
<div class="content-wrap"><!-- new content wrap div -->
<img src="images/profile-generic.jpg" alt="Your Name">
<div class="summary">
...
</div>
</div><!-- close contact wrap div -->
</section>
```
Then apply the styles to `.content-wrap` instead of `.profile`. Let's add some padding while we're at it too.
```
.content-wrap {
width: 1000px;
margin: 0 auto;
padding: 60px 0;
}
```
##Exercise #4: Content wrappers! (15mins)
Add the `.content-wrap` to each section *except* the `header`. We'll discuss why the header doesn't need it very soon.
First, let's go over how to collapse code blocks and tab multiple lines at the same time in Sublime first, to help make the addition of this markup a little easier.
Your page should look something like this: [example 4](project/examples/4a-content-wrap.html).
width & max-width, px vs %
The content is all nice and centered now but what happens when the browser window is smaller than the set width? Let’s look at the difference between the max-width
and width
property and using percentages and pixels.
Minimize the screen and see how the box responds. Then change the width to a percentage value less than 100% and try it again.
Lorem ipsum dolor sit amet.
##Class exercise
Update the `.content-wrap` styles to include `max-width` and update `width`.
```
.content-wrap {
max-width: 1000px;
width: 90%;
margin: 0 auto;
padding: 60px 0;
}
```
Your page will now look like this [example](project/examples/4b-content-wrap.html). Minimize the screen to test the updates.
Now we've created a reusable style that will help to keep our CSS nice and neat because we can apply this class where ever this style is required.
## The Dangers of "div-itis"
Be careful of "divitis"! Use the `<div>` to *group* related elements to be styled *together* as one section. If you need to style a single element, like an `<h1>` for example, just style that element directly. The browser sees every element as a "box" so there's no need to put a box around a box!
A good rule of thumb is to only add what you need. It's much easier to add more than to remove extra markup.
```xml
<div class="title">
<h1>Heading</h1>
</div>
```
can just be
```xml
<h1 class="title">Heading</h1>
```
##Avoid code bloat

##Update header & heading styles
In the case of the `header` section, we can apply `text-align: center` instead of adding the `.content-wrap` div. Since the content is short, we don't have to worry about containing it, therefore, avoiding "divitis". Also, adjust the padding to add space in the header. The final code for header should look like this:
```
header {
background: #2c3e50;
text-align: center;
padding: 150px 0;
}
```
While we're here, let's remove all of the default margins for the headings to get more control over how the spacing later on. Add `margin: 0` to the existing code block for the headers.
```
h1, h2, h3 {
font-weight: 400;
margin: 0;
}
```
Your header should look similar to [example 5](project/examples/5-header.html):

Lunchtime!
Need some time to check your work?
Take a look in the examples folder. We are now up to 5-header.html & 5-header.css.
Also, you can prepare for the next exercise by picking two images to use as the background images for your page or just choose from the images included in your project > images. Here’s the link to the final project for reference.
Resources for free images:
This lunchtime exercise will give learners a chance to catch up if needed and a chance to find images to personalize their site without taking up class time. The afternoon covers a lot of material and this will help speed it along. You should aim to hit lunchtime between 12:15 - 12:30pm. A 45 min lunch is recommended.
##Class Exercise: Background images
So far we've used `background` for colours but it can also be used for setting background images.
```
background-image: url(path/to/file.jpg); /* longhand */
background: url(path/to/file.jpg);/* shorthand */
```
Since our CSS file in *inside* a folder, use `../` to go *up and out* of the folder to get to the image files.
Let's add a background image to the `body` of your page. There are a few images in your **project > images** folder to choose from or your own.
```
background: url(../images/background-1.jpg);
```
See how the image repeats? Let's fix that.
##Class Exercise: Background Images (continued)
To keep the image from repeating, use `background-repeat` or just add it to the shorthand `background` property.
```
/* shorthand */
background: url(../images/background-1.jpg) no-repeat;
/* longhand */
background-image: url(../images/background-1.jpg);
background-repeat: no-repeat;
```
Now the image doesn't stretch all the way across the page but before we update that, let's try adding one more style. Add "fixed" to your shorthand markup. Check your page and scroll. What happens to the image?
```
/* shorthand */
background: url(../images/background-1.jpg) no-repeat fixed;
/* longhand */
background-image: url(../images/background-1.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
```
##Background-size
CSS3 introduced the `background-size` property which not only allows us to change the size of the image but also makes the background images fluid and flexible . The syntax is:
```
background-size: width height;
```
The default values for width and height are `auto` and retains the original image dimensions. If only one value is defined, it is assumed to be the `width`. The height will be set to `auto` and the image will keep its aspect ratio.
There are several ways to define sizing dimensions using px, percentages, keywords, etc.
`background-size` is the longhand property. To include it in the shorthand `background` property, it *must* be included after `background-position`, separated with the `/` character.
```
header {
background-image: url(../images/background-1.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50%;
background-size: 100%;
}
```
```
header {
background: url(../images/background-1.jpg) no-repeat fixed 50% / 100%;
}
```
If no background position value is being used, background-size won't work in the shorthand property so in this case, it may be less error prone to add it via the longhand property.
```
header {
background: url(../images/background-1.jpg) no-repeat fixed 50%;
background-size: 100%;
}
```
##Class Exercise: Background-size
This looks great... until you minimize the screen. This is where using the keyword, `cover` will work better.
`cover` scales the image to fit the entire container but, if that has a different aspect ratio, the image will be cropped.
Let's update the background-size to `cover`. Your code should now look something like this:
```
background: url(../images/background-2.jpg) no-repeat fixed 50%;
background-size: cover;
```
And your page should look similar to [Example 6](project/examples/6-background.html).
**Extra resource**: https://developer.mozilla.org/en/docs/Web/CSS/background
##CSS Float Property
Remember, block-style HTML elements like `<p>`, `<div>` and `<section>` automatically start on a new line and stack on top of each other. To get two block elements to align side-by-side, `float` can be used.
CSS floats can float elements left or right.
**However**, we have to break the *natural stacking flow* when an element is floated. This will cause any element *after* the floated element to try to move up beside it or just not display properly because we've disrupted the natural stacking flow. The parent container will also collapse.
**Also**, if no width set, the element will float but the width will automatically be the width of its content.
Float, Clear and Clearfix
First we have to break it, then put it back together. One of the most confusing CSS concepts is when to use clear:both
and the .clearfix
class. Rule of thumb: if there's is an element that follows the floated element, apply clear: both
to that element. If all the elements need to be floated, apply the .clearfix
class to the parent element.
Click on the Edit is JSFiddle to open the example. Let's go through the instructions.
Let's add this clearfix snippet to our CSS file to use it later.
Want to know more about the clearfix trick and clearing floats? Here you go:
http://css-tricks.com/snippets/css/clear-fix/
http://www.sitepoint.com/clearing-floats-overview-different-clearfix-methods/
##Descendant selectors
**Descendant selectors** - Matches any element that is a *descendant* of the element declared before it.
```css
p a {
/* targets only a tags nested inside of p tags */
}
.classname a {
/* targets only a tags nested inside any element with the matching classname */
}
```
**Protip:** Just like Inception, never go more than three levels deep!
```
nav ul li a span {
/* NOOOOOOOOOOO */
}
```
Feel free to skip a level but be mindful of specificity rules. For example, `nav ul li a` would override `nav a`. It’s generally easier to start with less specific selectors and make them more specific, as needed, rather than starting with very specific selectors and adding extra markup or classes to try to override the styles.
##Class Exercise: Floats
1. Add a float to your profile image so the text can wrap around it. What happens to the parent element when a child element is floated?
```
.profile img {
float: left;
}
```
1. Add the `clearfix` class to the parent element.
1. Make the image a relative size and add margin to create space between the image and text.
```
.profile img {
float: left;
width: 27%;
margin-right: 3%;
}
```
1. If the text is longer than the image, it will wrap around it. Put a width on the profile summary and float it too. (If you want the text to wrap around the profile image, skip this step.)
```
.summary {
width: 70%;
float: right;
}
```
##Exercise #7: Add More Floats and borders (20mins)
Add floats to the **Work Experience** section. Here's a link to the [final project](project/final.html) for reference and some hints to get you started:
In the HTML, the `.details` element contains the info that should be displayed on the left and the `.description` element contains the content to be displayed on the right. Floats can be applied to achieve this. Remember, when floating elements, declare a width as well.
What happens when elements are floated? The **parent element** *collapses* so make sure to *fix* that as well!
```
<div class="item">
<div class="details">
Company name, date, etc
</div>
<div class="description">
Job description
</div>
</div><!-- close .item -->
```
**Bonus:** If you have some extra time, follow these instructions for adding a border or tweak some font styles!
* Each Work Experience item is contain in an element with the `.item` class. Create a new declaration block for `.item` and add the `border-bottom` property to it. The syntax is: `border-bottom: size style color;`
```
.item {
border-bottom: 1px solid #ccc;
}
```
**Extra Bonus:** To make sure that all the **Work Experience** items have a border *except* the last item, use a **[pseudo-class selector](http://www.w3.org/wiki/CSS/Selectors/pseudo-classes/:last-child)**, `:last-child`. Note the syntax below.
```
.item:last-child {
border-bottom: none;
}
```
Your page should look something like this: [Example 7](project/examples/7-floats.html).
##More Background Styles
It's time to get rid of these test background colours and put in some nicer looking styles.
For the **Profile** section, add opacity to the background colour. Since the HTML for this section is nested inside of the `body` tag, adding opacity to the Profile section will show the `body` tag's background image behind it.
Use the `background` property but with an `RGBa` value. The `a` represents the alpha transparency. (There is an `opacity` property too but it makes the text opaque too so we'll use `background` instead).
```
.profile {
background: rgba(0,0,0,0.8);
}
```
Exercise #8: Background, colours, border (20mins)
- Update the Work Experience and Education section with the same background colour. The sample project is using a very light gray (#fefefc).
- Change the font colour of the Profile, Skills & Contact section to white or #ffffff. (Try combining selectors for shared styles.)
- Add another background image to the Skills section. Don’t worry about the overlay effect right now. Just add the image.
- Add an underline to the
<h2>
headings, #cccccc or a colour of your choosing.
- Update the background colour for the Contact section. Use #111111 or a colour of your choosing.
- Pick an accent colour and apply it to all links (
a
element).
Colour inspiration:
http://colours.neilorangepeel.com/
http://flatuicolors.com/
If you get stuck, ask a mentor! Don’t worry if you don’t finish, we’ll go through it together as a class.
Your page should look similar to this: Example 8.
Have a class discussion after the exercise time is up. Go over the steps as a class and ask people if they want to share any questions, comments or gotchas.
##CSS3 Properties: border-radius
The introduction of CSS3 brought in new ways to do things that previously had to be done in Flash, JavaScript or complicated hacks.
Let's start with `border-radius`. Once upon a time, rounded corners required cutting images with transparent backgrounds and blah blah blah... Now we can do it with one line of CSS! Add this style to the existing declaration block for the profile image. Percentages or pixel values can be used. The bigger the number, the more rounded the corners will be. To get a perfect circle, set the `border-radius` to 50% and the original image must also be a square (or else it will look oval).
```
.profile img {
border-radius: 50%;
}
```
Let's add a border and some padding. Remember, padding adds space *inside* of an element.
```
.profile img {
border-radius: 50%;
border: 1px solid #ddd;
padding: 4px;
}
```
##CSS3 Vendor prefixes
In some cases, a standard CSS property may require an addition of a browser specific prefix. For example, the various prefixes for different browsers are as follows:
* Chrome & Safari: `-webkit-`
* Firefox: `-moz- `
* Internet Explorer: `-ms-`
Not all properties require these prefixes and as newer browser versions are released, support for many of these prefixes are no longer required. Here are some handy resources.
* [caniuse.com](http://caniuse.com)
* [css3please.com](http://css3please.com/)
* [-prefix-free](http://leaverou.github.io/prefixfree/) - note, doesn't work **locally** in Chrome.
* [css-tricks.com/how-to-deal-with-vendor-prefixes](http://css-tricks.com/how-to-deal-with-vendor-prefixes/)
Profile Heading Update
Let’s update the <h2>
tag in the profile section and give it a style different from the other headings. First, we’ll override the bottom border. We need to use a selector that is specific to the profile section. Add a background color too. Try using your accent colour.
.profile h2 {
border: none;
background: #2980b9;
}
Headings are block level elements so by default, they are going to want to span 100% width of its container. We could set a width value on it but what if we change the greeting? Then we’d have to set the width again. Inline elements are as wide as their content.
In CSS we can use display: inline-block;
to access the block and inline behaviors and change how the h2 is displayed. Add some padding too.
.profile h2 {
border: none;
background: #2980b9;
display: inline-block;
padding: 10px 20px;
}
Read more about inline & block elements and the display property here.
##:hover Pseudo Selector
Let's try adding some changes on hover using the `:hover` [psuedo-class selector](http://www.w3.org/wiki/CSS/Selectors/pseudo-classes/:hover).
Psuedo selectors need to be attached to an element with a colon (`:`) with *no* space. A common use for this selector is for links. Let's add a colour change on hover.
```
a:hover {
color: #ffffff;
}
```
CSS Transition
The transition property can be used to change values over a specified duration making the transition appear less abrupt. Hover over this paragraph to see the transition. Experiment and change some of the values below.
transition: [transition-property] [transition-duration] [transition-timing-function] [transition-delay];
More about transition: http://css-tricks.com/almanac/properties/t/transition
##Class exercise: hover & transition
Add the transition property to the hover effects then try hovering over your links.
Your page should look similar to [example 9](project/examples/9-css3.html).
```css
a {
color: #2980b9;
transition: all 0.5s ease;
}
a:hover {
color: #ffffff;
}
```
Gradients
background
can also be used to create a gradient. Using CSS gradients instead of an image file, is better for flexibility and performance. Gradients are usually one color that fades into another. With CSS you can control the direction of the fade, the colors, as well as where the color changes happen.
Gradients are set using the background-image
property. The shorthand background
property will also work.
To set the values, use linear-gradient(color, color)
to set the start and stop colour. The axis defaults at a top-to-bottom angle, though it is also possible to change the direction of the axis. To change the direction to left-to-right, pass an additional parameter at the beginning of linear-gradient()
starting with the word "to" and the direction. (ex. "to right")
background-image: linear-gradient(to right, red, blue);
In the example below, try putting a start and stop colour. Then try changing the direction.
Learn all about gradients here: http://css-tricks.com/css3-gradients/
Gradients and Background Images
In our Skills section, the text is hard to read on top of the background image. We can use gradients and set multiple background images to achieve this effect.
Declare the gradient first so it can sit on top of the image. We also want to see the image through the gradient so use RGBA color values to set the alpha transparency.
##Exercise #10: Gradient & more floats (15 mins)
1. Using the previous example, add a gradient effect to the **Skills** section to make the text on background image more legible.
1. In the **Skills** section, there are two options, a `.skills-list` option and a `.skills-circle` option. Hold off on the circle option for now but for the list option, add floats to the `.column` class to get the **three** lists to line up side by side. We'll need to set the `width`, `float` and use the `clearfix` class.
Here's what your page should look like: [example 10](project/examples/10-skills-section.html).
See below for final code but only if you get stuck!
```
.skills {
background: linear-gradient(rgba(0,0,0,0.8), rgba(0,0,0,0.8)),url(../images/background-4.jpg) no-repeat fixed;
background-size: cover;
}
```
```
.skills .columns {
width: 33.33%;
float: left;
}
```
```xml
<div class="skills-list clearfix">
<h3>List Option</h3>
<div class="columns"><!--float this class! -->
<h4>Best at:</h4>
<ul>
...
</ul>
</div>
...
</div>
```
##Positioning in CSS
Sometimes floats and display just doesn't cut it.
The `position` property can be used to place elements in specific spots on the page without affecting the elements around it the way floats do. There are three options: `relative`, `absolute` and `fixed`. Elements are all `static` by default.
`position` is used in conjunction with offset properties: `top`, `right`, `bottom`, and `left`. These are use to identify where an element will be positioned.
Today we'll be using a fixed position. To learn more about position, [go here](framework/extras-positioning.html).
Position: fixed
When positioning an element as fixed
, it will always be positioned to the viewport and will always stay fixed on the page, even on page scroll. Try adding a top
value (or any other directional offset property: right
, bottom
, left
).
<div class="box"></div>
##Class Exercise: Download PDF resume
Some people may still be interested having a hard copy of your resume, so let's add an option to download a copy. Go back to your HTML document and add a link to a copy of the resume. In your projects folder, there is a **resume.pdf** that can be used as a placeholder or use yours if you have it handy.
Use the anchor tag to link to your resume file. You can also add a new HTML5 `download` attribute to trigger a download right away! Also, give it a class to apply unique styles to it.
```xml
<a class="download" href="resume.pdf" download>Download resume (pdf)</a>
```
Class Exercise: Position and style download link
Use fixed positioning for the link to make it always available as the user is scrolling down the page.
What properties & values are needed to position this element to the top right of the page?
.download {
position: fixed;
top: 0;
right: 0;
}
To style this download link to look more like a button, follow these instructions here.
The slides for further styling of the download link have been moved to extras/homework section because it doesn't cover any new concepts. This was moved to make time to introduce icon fonts.
##Icon fonts
Icon fonts are an easy way to add imagery to your web page but still have the flexibility of styling properties like size and colour using CSS since they *are* fonts!
There's many to choose from but today we'll use Font Awesome:
[http://fortawesome.github.io/Font-Awesome/](http://fortawesome.github.io/Font-Awesome/)
Under **[Get Started](http://fortawesome.github.io/Font-Awesome/get-started/)**, there are different options for adding the font files. If using the CDN, remember to add the "http" to make it work when you run your page "locally" (on your computer).
To use, [pick an icon](http://fortawesome.github.io/Font-Awesome/icons/) and copy the supplied markup and class and that's it! All of the social icons in the footer of your project's index.html file are included with an icon font.
##Class Exercise - Resetting List Styles
Add some flair to the skills list by replacing the default bullets with an icon.
To remove the default bullet points, use the CSS property and value, `list-style-type: none;`. The `ul` is the selected element since it is used to create the list. Lists also have default padding to create the indent, so reset that by using a value of 0.
Since we want to remove the bullets from all the lists in this section, we can target them all at once using a **descendant selector**. We can use `.skill`, since that's the class for the entire section, and `ul` to target all the lists.
```css
.skills ul {
list-style-type: none;
padding: 0;
}
```
##Exercise #11: Adding Icon Fonts (15mins)
Now that the bullets have been removed, let's add a checkmark. Visit [Font Awesome](http://fortawesome.github.io/Font-Awesome/) and go to **Icons** to get the code.
Copy the markup and add it to your HTML file, where ever you want the icon to appear. In this case, we want it in each *list item* (`li`).
For this exercise, add the check marks (or whichever icon you'd like to use) to each list item and use the CSS `color` property to change the color of *only* the icons.
**Bonus:** Try center aligning the headings and lists like in the [final project](project/final.html).
**Extra Bonus:** Try changing the color or the `h4` subheadings.
Your page should look similar to [Example 11](project/examples/11-icon-fonts.html).

##Next Steps
Though we've covered a lot of material today, there are more ways to give your HTML resume that extra personalization and polish. Here are some extra features you can try out:
1. The final example has a circle option for displaying your skills. See instructions [here](framework/extras-circles.html).
2. Try out some more [animation effects](framework/extras-animations.html).
3. Add a [favicon](http://blog.teamtreehouse.com/how-to-make-a-favicon).
4. Style your download link to look more like a button. [See instructions here](framework/extras-download-btn.html).
Also, there are many many ways to select elements that go beyond descendant selectors, classes and ids. See a few examples [here](framework/extras-advanced-selectors.html).
##Resources
Here are some resources to help dive deeper into HTML & CSS:
* [Learn to Code HTML & CSS](http://learn.shayhowe.com/)
* [Codecademy](http://www.codecademy.com/)
* [Treehouse](http://teamtreehouse.com/)
* [Code School](https://www.codeschool.com/)
* [HTML and CSS: Design & Build Websites](http://www.htmlandcssbook.com/) (book)
* [CodePen](http://codepen.io/)
* [CSSDeck](http://cssdeck.com)
##Getting your site online
You will need to register a domain name (www.mysite.com) and get hosting. Here are a couple domain & hosting options:
* [hover.com](http://hover.com/ladiescode)
* [dreamhost.com](http://www.dreamhost.com/r.cgi?205190)
* [bluehost.com](http://www.bluehost.com/)
To get your files online, you will need upload your files to your newly purchased hosting server. There are a few pieces of information you will need and are usually provided to you by your hosting service provider.
* FTP Address
* Username
* Password
Here's a nice tutorial getting your files online: [FTP For Beginners: How to Upload Your Files](http://webdesign.com/ftp-for-beginners-how-to-upload-your-files/)
Feeling adventurous? Try [Hosting Static Sites on Github for Beginners](http://thephuse.com/development/hosting-static-sites-on-github-for-beginners/).