What are the three parts that make up The CSS Rule?
What is the shorthand for the CSS font property?
p {
font: style weight font-family;
}
What does a complete link (anchor) element look like?
<a href="http://google.com/" target="_blank" >This goes to google</a>
ID -- Should only apply to one element on a webpage, i.e., a webpage only has one footer.
The "#" is how you tell CSS "this is an id."
Class -- Lots of elements can have the same class, i.e., There can be many warnings on one webpage.
The "." is how you tell CSS "this is a class name."
.align-right{
text-align:right;
color: purple;
font-weight: bold;
}
<div class="align-right">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
<p>Sed do eiusmod tempor incididunt ut labore et dolore.</p>
</div>
<p>Magna aliqua. Ut enim ad minim veniam.</p>
<p>Quis nostrud exercitation ullamco.</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit
Sed do eiusmod tempor incididunt ut labore et dolore.
Magna aliqua. Ut enim ad minim veniam.
Quis nostrud exercitation ullamco.
Let's add some styling your site specific to each div class in your HTML.
Style the content in the header, content area, and footer to have different CSS properties.
ex. Change the background color of your header div.
So far, we have mostly seen "block" elements. They appear on the next line, like paragraphs and divs.
There are also "inline" elements. They appear on the same line that they are written on.
HTML5 offers new elements for better document structure and semantics
Some of the most commonly used new tags include:
<header></header>
<nav></nav>
<article></article>
<section></section>
<main></main>
<footer></footer>
A full list can be found here.
A page divided using HTML 5 elements might look like this:
<!doctype html>
<html>
<head>
<title>Sample Page</title>
</head>
<body>
<header>
<h1>My Page Title</h1>
</header>
<main>
<p>The main content</p>
</main>
<aside>
<p>Some stuff in a sidebar</p>
</aside>
<footer>
<p>Copyright me</p>
</footer>
</body>
</html>
Span is used to apply a specific style inline
.highlight{
color:teal;
}
<p>Paragraph with <span class="highlight">teal</span> text.</p>
Paragraph with teal text.
Let's add some spans to our content to help highlight some text.
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.
Syntax:
selector:pseudo-class{
property:value;
}
Example:
a:link{
text-decoration: none;
}
a:link {color:#FF0000;} /* unvisited link */
a:visited {color:#00FF00;} /* visited link */
a:hover, a:focus {color:#FF00FF;} /* mouse over or select with keyboard*/
a:active {color:#0000FF;} /* selected link */
a:hover MUST come after a:link and a:visited in the CSS definition to be effective!
a:active MUST come after a:hover in the CSS definition to be effective!
Add pseudo classes to your links
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout.
The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.
Space between the border and the content
Notice that the padding 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;
Four values
padding: top right bottom left;
Three values
padding: top right/left bottom;
Two values
padding: top/bottom right/left;
One value
padding: all;
padding: 10px 20px 30px 40px;
Try adding some padding to the div with the class that has your main content.
Remember: you can write out "padding-left", "padding-right", etc. or you can use shorthand declarations.
The edge around the box.
Borders are specified as "thickness, style, color."
A solid red border
border: 1px solid #ff0000;
A thick dotted black top border
border-top: 4px dotted #000000;
Two different border styles
border-top: 1px solid #ff0000;
border-bottom: 4px dotted #000000;
border-width: 10px;
border-style: dashed;
border-color: #666666;
You can specify each property separately, or all three together.
Try adding a border to your <header> element as well as some padding.
Experiment with different border styles, thicknesses, and positions.
The transparent area around the box that separates it from other elements by creating whitespace. It can be used to horizontally center an element as well.
15 pixels on all sides
margin: 15px;
10 on top, 5 on right, 3 on bottom, 5 on left
margin: 10px 5px 3px 5px;
10 pixels on top
margin-top: 10px;
If a margin is set to auto on a box that has width, it will take up as much space as possible.
CENTERED
margin: 0 auto;
width: 200px;
This box will be centered.
Wrappers are a good way to center content if the screen width is wider than your content.
.wrapper {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
Try adding some margin to your <footer> element.
Notice how margin pushes the footer away from other content but the element stays the same size;
Then center your entire document in the browser by adding a wrapper class with auto margin, width and a max-width.
If you want two block level elements to be side by side, you need to float both elements..
width: 25%;
float: left;
width: 75%;
float: left;
This is a long paragraph text that is next to an image that is floating to the left. This is an image of Baby Groot. Groot was a Flora colossus from Planet X, the capital of the branch worlds. The sapling that would come to be known as "Groot" came from an "Enobled Sap-line" and gifted in quasi-dimensional super-positional engineering...at least, according to Maximus the Mad. Groot did not get along with his fellow saplings, instead preferring the company of the "Maintenance Mammals" who the other saplings treated with prejudice. After Groot killed another sapling to defend a maintenance mammal it was brutalising, as well as releasing a human subject that was kidnapped for scientific purposes, he was exiled of the planet by the "Arbor Masters". With no place to go, Groot set to explore other galaxies.
clear: right;
clear: left;
clear: both;
A clearfix is applied to pseudo-class :after of a div that contains two elements that are floating next to each other.
It's generally used in float layouts where elements are floated to be stacked horizontally.
.wrapper:after {
content: '';
display: table;
clear: both;
}
Be sure to apply this to the div that is containing your two elements that are floating next to each other.
Let's float our side bar and content area so they are displayed next to each other.
Notice how the footer no longer is displayed correctly. Add a clearfix to your wrapper class that contains the floating divs.