Positioning
The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element's content is too big.Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method.
There are four different positioning methods.
Static Positioning
HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page.Static positioned elements are not affected by the top, bottom, left, and right properties.
Fixed Positioning
An element with fixed position is positioned relative to the browser window.It will not move even if the window is scrolled:
Example
p.pos_fixed
{
position:fixed;
top:30px;
right:5px;
}
{
position:fixed;
top:30px;
right:5px;
}
Relative Positioning
A relative positioned element is positioned relative to its normal position.Example
h2.pos_left
{
position:relative;
left:-20px;
}
h2.pos_right
{
position:relative;
left:20px;
}
{
position:relative;
left:-20px;
}
h2.pos_right
{
position:relative;
left:20px;
}
Try it yourself »
Relatively positioned elements are often used as container blocks for absolutely positioned elements.
Absolute Positioning
An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>:Example
h2
{
position:absolute;
left:100px;
top:150px;
}
{
position:absolute;
left:100px;
top:150px;
}
Absolutely positioned elements can overlap other elements.
No comments:
Post a Comment
its cool