Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
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.
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;
}
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.
When you use positioning to move elements out of the normal flow of content, elements can overlap. You can change the order of overlapping with z-index.
The element with highest z-index goes on top.
.bottom{
position: absolute;
bottom: 10px;
left:60px;
background-color: yellow;
}
.top{
position: absolute;
bottom: 15px;
left:60px;
background-color: green;
z-index: 2;
}
Let's add some positioning.
Let's create a div that contains an image and a caption, and position the caption absolutely overtop the image.
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.
Please take a few moments to fill out this survey of the workshop: http://bit.ly/1uKkmeh
Find me:
@row4food
row4food@gmail.com