To describe the look and formatting of a document written in a markup language, eg. hypertext markup language (html)
We can change the colors, sizes, positions, and formatting of any of our HTML elements including the body, paragraphs, links, and images
Behold:
Godric Gryffindor
Godric Gryffindor
samewebsite/page1.html
Jake
Cassie
Ax
samewebsite/page2.htm
Tobias
Rachel
Marco
let's create a new file with the extension .css so we can keep all of our styles there
Let's break this down:
<link rel='stylesheet' type='text/css' href='style.css'>
p {
color: red;
color: #ff0000;
color: rgb(255, 0, 0);
}
The color property changes the color of the text.
Color name
Hexadecimal value
RGB value
Named colors such as: black, blue, gray, green, purple, white, etc.
The background-color property changes the color of the background.
p {
background-color: black;
background-color: #000000;
background-color: rgb(0,0,0);
}
The font-family property defines which font is used.
p {
font-family: 'Times New Roman';
font-family: serif;
font-family: 'Arial', sans-serif;
}
Specific font name
Generic name
Comma-separated list
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;
}
but what if i have list items that I want to make different colors?
What then?
-
Yellow Zest
-
Green Apple
-
Blueberry
-
Link 1
-
Link 2
-
Link 3
#green-apple {
color: rgb(0, 255, 0);
}
#blueberry {
color: rgb(0, 0, 255);
}
.navigation {
list-style: none;
}
.navigation-link {
font-size: large;
}
Content
Content
Main Heading
Paragraph with yellow text.
Space between the border and the content
Adds to the total width of the box.
/* 15 pixels on all sides */
padding: 15px;
/* 10 pixels on top only */
padding-top: 10px;
/* 10 on top, 5 on right, 3 on bottom, 5 on left */
padding: 10px 5px 3px 5px;
/* One value */
padding: all;
/* Two values */
padding: top/bottom right/left;
/* Four values */
padding: top right bottom left;
padding: 10px 20px 30px 40px;
The edge around the box, specified as 'thickness, style, color.'
/* a solid red border */
border: 1px solid #ff0000;
/* a thick dotted black top border */
border-top: 4px dotted rgb(0, 0, 0);
border-width: 10px;
border-style: dashed;
border-color: #666666;
You can specify each property separately, or all three together.
The transparent area around the box that separates it from other elements.
15 pixels on all sides
/* 15 pixels on all sides */
margin: 15px;
/* 10 pixels on top only */
margin-top: 10px;
/* 10 on top, 5 on right, 3 on bottom, 5 on left */
margin: 10px 5px 3px 5px;
If a margin is set to auto on a box that has width, it will take up as much space as possible.
Centered
width: 300px;
margin: auto;
Flush Right
width: 300px;
margin-left: auto;
margin-right: 5px;
Let's add some padding, borders, and margins to our divs.
Let's center our entire document in the browser.
Sets the width of an element.
Does not include padding or borders, remember these add to the width.
Sets the height of an element.
Does not include padding or borders, remember these add to the width.
Add a width & height to our divs.
Use IDs to target each div with CSS
p em {
color: yellow;
}
Selects all em elements that are within a paragraph
This is important.
body {
background-attachment: fixed;
background-image: url(milkway_splash.jpeg);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
Below a <blockquote> is floated to the left, allowing text to wrap around it on the right
.float {
float: left;
width: 200px;
background: yellow;
}
If you want two block level elements to be side by side, you need to float both elements. One left, and one right.
clear: right;
clear: left;
clear: both;
.float {
float: left;
width: 50px;
background: yellow;
}
.clear-left {
clear: left;
}
Let's float our side bar and content areas.
Changing the format of a link when you hover over it is accomplished by using pseudo-classes.
CSS pseudo-classes are used to add special effects to some selectors.
selector:pseudo-class {
property: value;
}
Example:
a:link {
text-decoration: none;
}
/* unvisited link */
a:link {
color: #FF0000;
}
/* visited link */
a:visited {
color: #00FF00;
}
/* mouse over link */
a:hover {
color: #FF00FF;
}
/* selected link */
a:active {
color: #0000FF;
}
Note: order matters
Add pseudo classes to your links
ul.navigation {
background-color: white;
display: block;
list-style: none;
margin-top: 0;
width: 100%;
height: 35px;
}
ul.navigation li {
display: inline-block;
float: left;
}
ul.navigation a {
color: black;
display: block;
padding: 10px;
text-decoration: none;
}
ul.navigation a:hover {
background-color: black;
color: white;
}
and look at some beautiful sites created using only HTML and CSS: