The default positioning property is static. Even when CSS in not applied, the default layout of the content is static which means it isn't really moving at all. The content is merely laid out in the order it appears.
Block elements are laid out vertically from top to bottom. Another important thing to note is that even if you adjust the width of the boxes/ content it will still be laid from top to bottom instead of side to side.
Inline elements are the opposite. They are laid out from side to side and can be specified by horizontal margins, NOT vertical ones.
Next positioning property is relative positioning. At first the element is laid out like your standard static position but then, it's shifted according to the top, bottom, left, and right properties.
Absolute position is the next positioning property and it literally is the ABSOLUTE position. What I mean is that not only does it not have any effect on the parent element or any elements that occur after in the same code, it is entirely removed from the document flow. This means that an absolutely positioned element will overlap other content unless you do something to prevent this action.
Finally, we have fixed position. Fixed position is more like a specialized version of absolute. Fixed means it fixed relative to the browser window rather than the containing element. This means that even if you scroll down a page, the content is in the exact same position as the browser window.
Another unique advantage when it comes to position is that you can use all four properties at the same time. This is done by specifying the distance from each edge of the positioned element to the corresponding edge of the containing block. You can also specify the position of one of the corners of the absolutely positioned box—say by using top and left—and then specify the dimensions of the box using width and height
Another important note about absolute positioning is about the containing block: which is the block box that the position and dimensions of the absolutely positioned box are relative to. For static boxes and relatively positioned boxes the containing block is the nearest block-level ancestor—the parent element in other words.
RELATIVE:
#div-1 {
position:relative;
top:20px;
left:-40px;
}
ABSOLUTE:
#div-1a {
position:absolute;
top:0;
right:0;
width:200px;
}
FIXED:
#div-1 {
height:800px;
}
#div-1a {
position:fixed;
width:380px;
}
RELATIVE + ABSOLUTE
#div-1 {
position:relative;
}
#div-1a {
position:absolute;
top:0;
right:0;
width:200px;
}
You can also use floats as a means of positioning as well as two to three column layouts.
No comments:
Post a Comment