Saturday, September 17, 2011

Playing with css: working with position absolute

If you always want an element at a certain place without relativity to any other element, then we use this property "position:absolute;". While playing around with "position absolute", I learned that we do not use "margin", instead we use properties such as "top, bottom, right and left".

For instance, I have an element with class "example", I use "position absolute" in it as:
Hello

We can also give "float" values to "absolute positions" like
float:left or float:right

2 comments:

  1. Position = absolute means you remove the element from the DOM flow and add it again. Eg, if you add an image with position: absolute in a paragraph, it will be removed from the DOM flow (in other words, it will not be contained inside the paragraph), and the rest of the DOM will be loaded as if the image was not there. Then, the image will be loaded, usually, it will be loaded at the top left corner of the screen. That is why you add 'top, bottom, right and left'.

    ReplyDelete
  2. @saksham: thanks for more information about it!

    ReplyDelete