Class 3
A quick file path exercise
<!doctype html>
<html>
<head>
<link href="pointB.css" rel="stylesheet" />
</head>
<body>
</body>
</html>
The rel attribute stands for relationship, since it specifies the relationship between the current document (the HTML) and the linked document/resource (the CSS)
File Path | What it means |
---|---|
<link href="pointB.css" rel="stylesheet" /> | pointB.css is located in the current folder |
<link href="css/pointB.css" rel="stylesheet" /> | pointB.css is located in a folder called css. The css folder is located in the current folder. |
<link href="css/other/pointB.css" rel="stylesheet" /> | pointB.css is located in a folder called other that is located in a folder called css that is located in the current folder. |
<link href="../pointB.css" rel="stylesheet" /> | pointB.css is located in a folder one level up from the current folder |
<link href="../../pointB.css" rel="stylesheet" /> | pointB.css is located in a folder two levels up from the current folder |
A folder is also called a directory
View design image »
Download PSD (optional; requires Photoshop) »
Go ahead and create your folders
Ignore the HTML and CSS files for now
Inline vs. Block
selector {
display: inline;
display: block;
}
Inline vs. Block
So far, we have mostly seen "block" elements
They appear on the next line, like paragraphs
There are also "inline" elements
They appear on the same line that they are written on
Inline vs. Block
See the Pen Inline vs. Block by Liz Shaw (@anythingcodes) on CodePen.
Block elements push sibling elements to another line. Inline elements allow sibling elements to sit to their right and left.
Click 'Edit on CodePen' to edit the above code.
(Don't worry, your changes can't overwrite anything!)
Inline vs. Block
Inline | Block | |
---|---|---|
Can have a set width and height | ✗ | ✔ |
Allow other elements to their left and right | ✔ | ✗ |
Force sibling elements to move to a new line | ✗ | ✔ |
HTML elements have default display values that the browser uses
Example: <span>
See the Pen Inline Element by Liz Shaw (@anythingcodes) on CodePen.
Example: <div>
See the Pen Block Element by Liz Shaw (@anythingcodes) on CodePen.
Forcing a block-level div's 'display' property to 'inline' »
Block-level elements are used to divide or section content within an HTML page
Group other elements within dividing elements to format them differently with CSS
See the Pen Layouts & Sections by Liz Shaw (@anythingcodes) on CodePen.
Common Examples:
Let's create block-level elements to separate content into different sections on our page
View design image »
Download PSD (optional; requires Photoshop) »
Changing the format of a link when you hover over it is accomplished by using pseudoclasses
selector:pseudoclass {
property: value;
}
CSS pseudoclasses are used to add special effects to some selectors
a:hover {
color: #F0C042;
}
Let's add a default link color and hover color to your links. Let's also add a font-family style to the body.
A Practical Example
15 pixels on all sides:
selector {
padding: 15px;
}
25 pixels on top only:
selector {
padding-top: 25px;
}
Four values:
selector {
padding: top right bottom left;
}
Two values:
selector {
padding: topAndBottom leftAndRight;
}
One value:
selector {
padding: all;
}
A Mnemonic for Four Values
10px on top, 5px on right, 3px on bottom, 15px on left:
div {
padding: 10px 5px 3px 15px;
}
See the Pen Padding by Liz Shaw (@anythingcodes) on CodePen.
Properties
You can specify each property separately:
selector {
border-width: 10px;
border-style: dashed;
border-color: grey;
}
Or with all three together:
selector {
border: 10px dashed grey;
}
A solid red border:
selector {
border: 1px solid red;
}
A thick dotted black top border:
selector {
border: 4px dotted black;
}
Two different border styles:
selector {
border-top: 1px solid green;
border-bottom: 4px dashed purple;
}
See the Pen Border by Liz Shaw (@anythingcodes) on CodePen.
15 pixels on all sides:
selector {
margin: 15px;
}
25 pixels on top only:
selector {
margin-top: 25px;
}
Four values:
selector {
margin: top right bottom left;
}
Two values:
selector {
margin: topAndBottom leftAndRight;
}
One value:
selector {
margin: all;
}
A Mnemonic for Four Values
The same mnemonic!
10px on top, 5px on right, 3px on bottom, 15px on left:
div {
margin: 10px 5px 3px 15px;
}
See the Pen Margin by Liz Shaw (@anythingcodes) on CodePen.
Let's add some padding, margins, and a border to the <h3>s in our project
If a margin is set to auto on a box that has width, the margins will take up as much space as possible
Centered
selector {
margin: auto;
width: 300px;
}
Sets the width of an element
Does not include padding or borders, since those add to the width
Remember: block elements respect width, while inline elements do not
Let's center our <h3>s and <section>s
Sets the height of an element
Does not include padding or borders, since those add to the height
Remember: block elements respect height, while inline elements do not
Inline vs. Block
Inline | Block | |
---|---|---|
Respect left and right margins | ✔ | ✔ |
Respect top and bottom margins | ✗ | ✔ |
Inline elements respect top and bottom padding, but it is relative to the baseline.
CSS Positioning, Flow, & Other
Coding Goodness