Below, a <blockquote>
is floated to the left, allowing text to wrap around it on the right
width
when floating an element—otherwise the element is likely to take up the whole width of the container and not appear floated..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.
width: 300px;
float: left;
width: 400px;
float: right;
right
, left
, both
) other elements cannot appear. clear: left;
to the paragraph.both
ensures the element doesn't wrap next to floats on either side.clear: right;
clear: left;
clear: both;
.float {
float: left;
width: 150px;
background: yellow;
}
.clear-left {
clear: left;
}
.clear-left
drops below the floated element.float
on your sidebar and content areas.static
by default.top
, bottom
, right
, or left
property specifications.In normal flow, inline
elements flow from left to right, wrapping to next line when needed.
<img src="img/otter.jpg"/>
<img src="img/otter.jpg"/>
<img src="img/otter.jpg"/>
...
<img src="img/otter.jpg"/>
<img src="img/otter.jpg"/>
In normal flow, block
elements flow from top to bottom, making a new line after every element.
<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
/bottom
/right
/left
properties.
.relative {
position: relative;
left: 80px;
top: 20px;
height: 100px;
background-color: yellow;
}
top
, bottom
, right
, or left
. 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 ancestor).
.top {
position: absolute;
top: -40px;
right: 10px;
background-color: yellow
}
.bottom {
position: absolute;
bottom: -40px;
left:60px;
background-color: green
}
top
, bottom
, right
, and left
.<html>
.Here's an example of an image with a caption absolutely positioned in front of it.
The containing div
has a position
of relative
, and the caption has a position
of absolute
.
The "fixed" value will take the element out of the normal flow and position it relative to the viewport.
footer {
position: fixed;
bottom: 3px;
left: 0;
height: 40px;
width: 100%;
}
Do you see the fixed footer in these slides?
Sometimes elements 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;
}
div
that contains an image and a caption.We love feedback! Please leave us some kind words and actionable suggestions.