<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
The DOCTYPE informs the browser that this file contains HTML5.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
The html tag wraps all content on the entire page and represents the start and end of an HTML document.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Content that will not be displayed to the user. (ie: keywords to help your website surface in search results and CSS to style content.)
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Content that will be displayed to the user.
Container HTML Element
Your Content
Self-Closing HTML Element
<tagname attribute="value">
A static website has two layers: HTML and CSS
HTML (Structure) vs CSS (Presentation)
CSS stands for Cascading Style Sheets
"Cascading" refers to the "Cascade", which determines which CSS rule gets applied to our HTML.
Use the <link> tag inside the <head> tags.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
HTML | uses tags | < > |
CSS | creates rules | { } |
Image from internetingishard.com
We will need:
Copy the following HTML
<!DOCTYPE html>
<html>
<head>
My Website
</head>
<body>
Welcome to my site!
First paragraph
Second paragraph
</body>
</html>
Type Selectors are used to select an HTML element type.
Below is a example of using a CSS Type Selector. This will set the background-color for ALL paragraphs.
p {
background-color: blue;
}
In the .css file, add a CSS rule that:
p {
background-color: blue;
}
But what if we only want one paragraph to be blue?
Below is an example of how to add a class attribute to an HTML tag.
Paragraph tag with a class attribute.
A class selector is written in the CSS file by placing a period (.) before the class name.
.my-class-name {
background-color: yellow;
}
In the .html file...
Add a class attribute, with the name "my-class-name", to the first paragraph tag.
First paragraph.
In the .css file...
.my-class-name {
background-color: yellow;
}
Type Selectors are very useful as they can target all <p> tags or all <h2> tags.
Class Selectors are important because they can differentiate between HTML elements of the same type.
First paragraph
Second paragraph
Add a class to the other <p> tag and set the background-color to a different color.
First paragraph
Second paragraph
Type and class selectors = Ability to share styles
Ability to share styles = Less Work for you!
Image from teamtreehouse.com
Buttons are a good example of when we want to share CSS styles.
Below is an example of how to add an ID attribute to an HTML tag.
Paragraph tag with an ID attribute.
An ID selector is written in the CSS file by placing a pound sign (#) before the ID name.
#my-id-name {
background-color: purple;
}
In the .html file...
First paragraph
In the .css file...
#my-id-name {
background-color: purple;
}
ID attributes can also be used as "fragment identifiers", which let's us link to another section on the same page.
Let's hop in the code and walk through an example.
In the .html file...
<body>
Top of the Page
Go to Top
</body>
To see this work, our page needs space between the top and bottom of the page. In the .css file...
.header {
height: 2000px;
}
p {
color: red;
}
.my-class-name {
color: blue;
}
#my-id-name {
color: purple;
}
CSS treats all HTML elements as boxes. Some of elements are treated as block boxes and others are treated as inline boxes.
Image from https://codeburst.io
Image from dovetailapp.com
Image from dovetailapp.com
Replace existing HTML with the following:
Headings Are Block Elements
Paragraphs are blocks, too. However, em and strong
elements are not. They are inline elements.
Block elements define the flow of the HTML document, while
inline elements do not.
Replace existing CSS with the following:
h1 {
background-color: lightgrey;
}
p {
background-color: lightgrey;
}
em {
background-color: lightblue;
}
strong {
background-color: lightblue;
}
This example demonstrates:
We can override the default box type of HTML elements with the CSS display property. For example, if we want to make an inline element behave like a block element.
em {
display: block;
}
To understand how browsers treats each HTML element as a "box", let's examine the CSS Box Model. This Box Model helps us see that each box is composed of four parts: content, padding, border and margin.
Image from internetingishard.com
To help us along the way, we'll use a helpful browser tool called the inspector To open the inspector, right-click on your website and select "inspect".
Content - the text, image or media content in the element.
This is content
Padding - the space between the box's content and its border.
h1 {
padding: 50px;
}
CSS properties that add padding to a specific side of the element.
h1 {
padding-top: 20px;
padding-bottom: 20px;
padding-left: 10px;
padding-right: 10px;
}
Image from internetingishard.com
h1 {
padding: 20px 10px;
}
Image from internetingishard.com
h1 {
padding: 20px 10px 20px 10px;
}
Border - The line drawn around the content and padding.
h1 {
border: 1px solid grey;
}
Image from internetingishard.com
h1 {
border: 1px dotted pink;
}
Like padding, there are properies that add a border to a specific side of the element.
h1 {
border-top: 1px solid pink;
border-right: 1px solid red;
border-bottom: 1px solid grey;
border-left: 1px solid green;
}
Margin - the space between an element and surrounding elements.
p {
margin: 50px;
}
Like padding, there are properies that add a margin to a specific side of the element.
h1 {
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;
}
The CSS properties padding, border, and margin can be written in the shorthand format, which accepts one to four values OR we can target a specific side.
h1 {
margin: /*top right bottom left*/
margin-top: /*top*/
margin-right: /*right*/
margin-bottom: /*bottom*/
margin-left: /*left*/
}
Build a section with a title, a paragraph, and a button.
Image from turing.io
Scroll for full content.
Proven Results
Turing is difficult, but worth it. 75% of our students graduate
within 7 months, and 92% graduate within 10.5 months. 69% of
graduates are employed full-time within 90 days of graduation.
By 180 days, the percentage jumps to 80%. They're not project
managers or off in a corner doing the stapling. They are
full-time software developers in careers they love. Their median
salary is $75K and, for most, that's nearly double their
previous salary.
We release our student outcomes semi-annually as founding
members of the Council on Integrity in Results
Reporting.
Proven Results
Assign a class to target specific text:
Proven Results
.header {
}
.header {
font-family: Helvetica, sans-serif;
font-size: 48px;
font-weight: bold;
text-align: center;
}
Add a class to target the remaining paragraphs
Turing is difficult, but (...etc...)
We release our student outcomes (...etc...)
Select the font
Center the text
.content {
}
.content {
font-family: Helvetica, sans-serif;
text-align: center;
}
2016 Student Outcomes Report
Add a class to target the button.
2016 Student Outcomes Report
Add a class to target the button.
.call-to-action {
text-align: center; /* hmmm... */
}
This does not work as we cannot center an inline element.
We can use the <div> HTML container element to group other HTML elements together.
Proven Results
Turing is difficult, but (...etc...)
We release our student outcomes (...etc...)
2016 Student Outcomes Report
Our current CSS should look like this:
.container {
text-align: center;
}
.header {
font-family: Helvetica, sans-serif;
font-size: 48px;
font-weight: bold;
}
.content {
font-family: Helvetica, sans-serif;
}
.call-to-action {
}
.call-to-action {
border: 1px solid #05c2d1;
padding: 10px 16px;
}
Links are inline elements, which means we can't adjust their vertical spacing.
But we can change the display type to "inline-block", which treats the width of the element as an inline element but allows us to apply a height.
.call-to-action {
border: 1px solid #05c2d1;
display: inline-block;
margin-top: 10px;
}
Set the color
Remove default browser styles applied to links
a {
color: #05c2d1;
text-decoration: none;
}
Set the max-width to limit how wide the text can expand.
When a width has been specified, setting the left and right margin as "auto" as tells the browser to automatically determine the left and right margins itself, which it does by setting them equally.
.container {
text-align: center;
max-width: 70%;
margin: 0 auto;
}
a {
color: #05c2d1;
font-weight: bold;
text-decoration: none;
}
.container {
line-height: 1.7;
margin: 0 auto;
max-width: 70%;
text-align: center;
}
.header {
font-family: Helvetica, sans-serif;
font-size: 48px;
font-weight: bold;
margin-bottom: 0;
}
.content {
color: #7c8c8e;
font-family: Helvetica, sans-serif;
}
.call-to-action {
border-radius: 4px; /* new */
border: 1px solid #05c2d1;
display: inline-block;
margin-top: 10px;
padding: 10px 16px;
}
Proven Results
Turing is difficult, but worth it. 75% of our students
graduate within 7 months, and 92% graduate within 10.5
months. 69% of graduates are employed full-time within 90
days of graduation. By 180 days, the percentage jumps to
80%. They're not project managers or off in a corner doing
the stapling. They are full-time software developers in
careers they love. Their median salary is $75K and, for
most, that's nearly double their previous salary.
We release our student outcomes semi-annually as founding
members of the Council on
Integrity in Results Reporting.
2016 Student Outcomes Report