What are a few different HTML tags?
Which tag is used to create a link to another page?
<p>
<link>
<a>
<america>
<a>
What are the two tags that nest directly within the <html>
tags?
<head>
and <body>
What is a relative versus absolute path?
Content: Text, Media
+ HTML: Structure + Semantics
+ CSS: Presentation + Design
+ JS: Interactivity
= Your Website
A website is a way to present your content to the world, using HTML and CSS to present that content & make it look good.
CSS = Cascading Style Sheets
CSS is a "style sheet language" that lets you style the elements on your page.
CSS is works in conjunction with HTML, but is not HTML itself.
All colored text, position, and size
CSS consists of style rules. Each style rule consists of a selector and declarations of property-value pairs:
selector {
property: value;
property: value;
}
For example:
body {
color: yellow;
background-color: black;
}
3 ways
"Inline"
"Embedded"
"External"
<p style="color:red">Some text.</p>
style
attribute.<head>
<style>
p {
color: blue;
font-size: 12px;
}
</style>
</head>
<head>
element.<style>
tag.<head>
<link rel="stylesheet" href="style.css">
</head>
main.css
<link>
to the file in the head of your index.html
file (Is this a relative or absolute path?)body {
background-color: turquoise;
}
Check your page and see what happens.
selector {
property: value;
property: value;
}
The selector is used to select which elements in the HTML page will be given the styles inside the curly braces.
p {
property: value;
}
Selects all paragraph elements.
img {
property: value;
}
Selects all image elements.
The color
property changes the color of the text.
p {
color: red;
}
The background-color
property changes the color of the background.
body {
background-color: hotpink;
}
Your browser can accept colors in many different ways:
Color name: | red |
Hexadecimal value: | #FF0000 |
RGB value: | rgb(255, 0, 0) |
HSL value: | hsl(0, 100%, 100%) |
Easily try out new colors directly in the browser:
The font-family property defines which font is used.
p {
font-family: "Times New Roman"; /* Specific font name */
/* or */
font-family: serif; /* Generic name */
/* or */
font-family: "Arial", sans-serif; /* Comma-separated list */
}
*When listing multiple fonts, always list a generic name last.
The font-size
property specifies the size of the font.
p {
font-size: 12px;
font-size: 1.5em;
font-size: 100%;
}
Pixels
"em"
Percentage
p {
font-style: italic;
font-weight: bold;
font-size: 10px;
font-family: sans-serif;
}
OR
p {
font: italic bold 10px sans-serif;
}
p em {
color: yellow;
}
Selects all em
elements that are within a paragraph:
<p>This is <em>important.</em></p> <!-- This would be selected -->
<h1>This is <em>important.</em></h1> <!-- This would not! -->
ul li a strong{
color: purple;
}
So what does that CSS mean? Fill in the blank:
"Find a ____inside a ___ inside a __ in an ___ list"
<ul>
<li><a href="programs.html">Our <strong>program</strong></a></li>
</ul>
Pseudo-classes can style elements based on their current state.
Syntax:
selector:pseudo-class {
property: value;
}
Example:
a:hover {
text-decoration: none;
}
a:link { color:#FF0000; } /* unvisited link */
a:visited { color: green; } /* visited link */
a:hover { color: purple; } /* moused over */
a:focus { color: purple; } /* selected with keyboard*/
a:active { color: blue; } /* activated link */
Note: a:hover
MUST come after a:link
and a:visited
in the CSS to be effective
You can group selectors to apply the same style to all of the selectors by separating them with commas:
a:hover, a:focus {
color: purple;
}
As a general coding principle, Don't Repeat Yourself.
To reuse CSS, we use IDs and classes.
id
-- Applies to one element on a webpage, i.e., a webpage only has one footer.
In CSS, you mark an id
selector with a "#
".
class
-- Lots of elements can have the same class, i.e., There can be many warnings on one webpage.
In CSS, you mark a class
selector with a ".
".
id
#site-footer {
property: value;
}
Selects the one element on the page with an id
of site-footer
.
<p id="site-footer">Copyright 2016</p>
^ The associated HTML
class
.warning {
color: red;
}
Selects all elements with a class
of warning
.
<p class="warning">Run away!</p>
^ The associated HTML
id
and a class
to a your HTMLWhat styles will each paragraph receive?
p {
color: orange;
font-family: sans-serif;
}
.info-paragraph {
color: blue;
background-color: orange;
}
#main-paragraph {
font-weight: bold;
color: green;
}
<p>Paragraph</p>
<p class="info-paragraph">Paragraph</p>
<p class="info-paragraph" id="main-paragraph">Paragraph</p>
Your browser assigns different priorities to CSS depending on the type of selector.
Your browser also assigns priority based on the specificity of the selection. More specific selectors have higher priority.
.main .sale .clearance p { /* Most specific */
color: red;
}
.header .title p {
color: green;
}
.footer p { /* Least specific */
color: blue;
}
The tie-breaker is rule order. Rules lower in the file overwrite rules higher in the file
a {
background-color: yellow;
}
a {
background-color: teal;
}
a { /* This rule wins */
background-color: black;
}
There are many more ways to select elements in different ways. Read more:
Many CSS properties have self-explanatory names:
Find more at: MDN: All CSS properties