Monday 28 April 2014

CSS absolute positioning

We do not have relative positioning in CSS. what I mean by that is the position:relative in css means the item is a reference for others. for example if you have an outer div with the follwing css:
#outerDiv {
    width: 770px;
    margin: 0 auto;
    position: relative;
    background: #fff url(../images/banner.jpg) no-repeat;
}

the above div will be in middle of page and it will be a start reference for other tags having absolute position.
#insideDiv{
    position: absolute;
    width:30px;
    background: #eee
    top: 0;
}

if in outerdiv we did not have  position:relative  the insidediv would start from body but when we have  position:relative it starts from outer div.

So Relative just means you are creating a reference for absolute positioning.

No comments:

Post a Comment