On Github girldevelopitcincinnati / gdi-cincinnati-refresher-htmlcss
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
1 This one's important
Network:RFGUEST
Password:SilverJoe's
Tell us about yourself.
A website is a way to present your content to the world, using HTML and CSS to present that content & make it look good.
HTML is the code that allows us to build websites.
If you 'view the source' of a page, you see this:
< >
Angle brackets. HTML.
Every piece of content involves these.
A paragraph is your content
<p>A paragraph is your content</p>
A paragraph is your content
<p>There's a tag on the left and a tag on the right.</p>
All elements "nest" inside one another
Whichever element OPENS first CLOSES last
So, you could put a link into a paragraph. Very common.
<p>I want you to visit <a href="http://google.com/">this site</a>, soon!</p>
What would that look like?
I want you to visit this site, soon!
The first thing on an HTML page is the doctype, which tells the browser which version of the markup language the page is using.
Here's the doctype we use to tell the browser "Hey, this is HTML5, buddy"
<!DOCTYPE html>
The head contains meta information about the page.
The body contains the actual content of the page.
<!DOCTYPE html> <html> <head> <title>Awesome Site!</title> </head> <body> Stuff goes here </body> </html>
Create a GDI folder on your desktop. Inside of that folder create a file called index.html. Open that file using Sublime Text, type this code in and save.
<p>This is an HTML element, right here</p>
<br> <img> <hr>
<!DOCTYPE html> <html> <head> <title>Awesome Site!</title> </head> <body> <p>Look at all of the elements!</p> <p>There are so many of them!</p> <br> <img> </body> </html>
Add these elements to index.html and save!
<a href="http://girldevelopit.com">GDI</a> <img src="my-picture.jpg"/>
<!DOCTYPE html> <html> <head> <title>Awesome Site!</title> </head> <body> <p id="title">Look at all of the elements!</p> <p class="sub-heading">There are so many of them!</p> <br> <img src="http://www.placecage.com/500/500"> </body> </html>
Add id="value" to the first p tag, class="value" to the second p tag and src="value" to the img tag in index.html and save!
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
{ }
Curly braces. CSS.
Every rule we create has a { and a }. Always.
It's how we tie our CSS to specific HTML elements
In this CSS, 'selector' is a rule to select HTML.
selector { }
"I want to select all the paragraphs."
"I want to select the list of recipe ingredients."
It's how we give a certain style to what we 'selected'
p { color: red; }
"I declare that this text shall be red!
"I declare this paragraph shall be aligned to the right!
selector { property: value; }
A block of CSS code is a rule.
The rule starts with a selector.
It has sets of properties and values.
A property-value pair is a declaration.
Declarations: Property and value of style you plan use on HTML element.
Declarations end with a semicolon
Declaration groups are surrounded by curly brackets.
selector { property: value; property: value; property: value; }
This is a 'rule' with three declarations.
p { property: value; }
Selects all paragraph elements.
img { property: value; }
Selects all image elements.
How can we identify a single item on the page?
By giving it an 'id'.
<p id="footer">This is the footer of our website, and we should probably style it in some way so it hangs out at the bottom.</p>
The 'id' of that paragraph is 'footer'
There can be only one.
We've basically 'named' this element so we can style it in our CSS document specifically.
ID's are selected with the # (hash) symbol.
#footer { property: value; }
Selects all elements with an id of "footer".
<p id="footer">Copyright 2011</p>
The associated HTML.
How can we identify a set of items on the page?
By giving each of them a 'class'.
<p class="warning">My text must be red, or else.</p> <p>I have no class.</p> <p class="warning">I beg you, redden me.</p>
The 'class' of two of them is 'warning'.
We can single out just 'warning' with some CSS...
.warning { color: red; }
Selects all elements with a class of 'warning'.
<p class="warning">Run away!</p>
The associated HTML.
The "#" is how you tell CSS "this is an id." #footer
The "." is how you tell CSS "this is a class name." .warning
<head> ... <link href="style.css" rel="stylesheet"> </head>
In your GDI folder, create a file called style.css and link it using the example above.
#title { font-size: 24px; color: red; } .sub-heading { font-size: 18px; color: green; } img { border: 1px solid black; }
In your GDI folder, create a file called style.css and link it using the example above. Now, open index.html in Chrome and look at the changes! Spend a few minutes adding your own elements and targetting them using CSS!
Space between the border and the content
The edge around the box, specified as "thickness, style, color."
The transparent area around the box that separates it from other elements.
Easy to remember:
The box model is Trouble
The box model is TRBL
Top Right Bottom Left
p { padding: 15px; }10 pixels on top only
p { padding-top: 10px; }10 on top, 5 on right, 3 on bottom, 5 on left
p { padding: 10px 5px 3px 5px; }
Four values
p { padding: top right bottom left; }
Two values
p { padding: top/bottom right/left; }
One value
p { padding: all; }
div { padding: 10px 20px 30px 40px; }
A solid red border
p { border: 1px solid #ff0000; }
A thick dotted black top border
div { border-top: 4px dotted #000000; }
Two different border styles
address { border-top: 1px solid #ff0000; } blockquote { border-bottom: 4px dotted #000000; }
15 pixels on all sides
p { margin: 15px; }
10 on top, 5 on right, 3 on bottom, 5 on left
p { margin: 10px 5px 3px 5px; }
10 pixels on top
p { margin-top: 10px; }
p { margin: 20px; padding: 30px; border: 1px solid red; }
Add this code to style.css and look at how if affects your paragraphs!
HTML elements are positioned static BY DEFAULT.
Static elements are positioned in the normal flow of the page.
Static elements ignore top, bottom, right or left property specifications. (So there's no trouble, get it?)
In normal flow, inline boxes flow from left to right, wrapping to next line when needed.
<img src="images/cookie1.png"/> <img src="images/cookie2.png"/> <img src="images/cookie3.png"/> ... <img src="images/cookie2.png"/> <img src="images/cookie3.png"/>
In normal flow, block boxes flow from top to bottom, making a new line after every box.
<p>Greetings</p> <p>Hello</p> <p>Hi there!</p>
Greetings
Hello
Hi there!
The "relative" value will still put the element in the normal flow, but then offset it according to top/left/right/bottom properties.
.relative{ position: relative; left: 80px; top: 20px; height: 100px; background-color: yellow; }
Make the word 'elements' shift out of place.
<p id="title"> Look at all of the <span class="shift">elements</span>! </p>
.shift { position: relative; top: -10px; }
Add this to your code and save. Try moving the word around using TRBL!
The "absolute" value will take the element out of the normal flow and position it in relation to the window (or the closest non-static element).
.top{ position: absolute; top: -40px; right: 10px; background-color: yellow }
.bottom{ position: absolute; bottom: -40px; left:60px; background-color: green }
Here's an example of an image with a caption absolutely positioned over top of it.
The containing div has a position of relative, and the caption has a position of absolute.
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.
<!DOCTYPE html> <html> <head> <title>Awesome Site!</title> </head> <body> <div id="navigation"> Nav </div> <div id="content"> <p id="title">Look at all of the elements!</p> <p class="sub-heading">There are so many of them!</p> <br> <img src="http://www.placecage.com/500/500"> </div> </body> </html>
Add this HTML to your index.html document and save!
#navigation { float: left; width: 20%; } #content { float: right; width: 70%; }
Add this CSS to your style.css document and save! Take a look at what changed and make your own changes!
p { clear: right; } p { clear: left; } p { clear: both; }
.float{ float:left; width:50px; background:yellow; } .clear-left{ clear:left }