5

In HTML,When you use the position:absolute css property in child block the absolute value is not taken from parent tag it refer from whole browser window. the sample code is shown below..

CSS

.parent {
    width: 400px;
    height: 400px;
    border: 1px solid green;
}

.child {
    position: absolute;
    width: 200px;
    height: 200px;
    border: 1px solid red;
    bottom: 0px;
}
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Rajkumar
  • 197
  • 3
  • 13
  • 3
    Why are you asking this question if you already know the answer? Anyone who even looks for the most basic `position:absolute` search query on Google will find that you need a `relative` container (or other non-`static`). The way I see it, you only asked this question to farm reputation from the system - you've gained 55 already! – Niet the Dark Absol Sep 30 '13 at 12:30
  • @Kolink: Posting a question that you know the answer to and then answering it is fine, but you're right in that this is a really basic and frequently asked question that can be answered with a simple Google search. – BoltClock Sep 30 '13 at 12:39
  • @Kolink it seems this is a kind of spam! – frogatto Sep 30 '13 at 12:40
  • @Kolink I post this to share my knowledge. – Rajkumar Sep 30 '13 at 12:41
  • 1
    @ABFORCE: Spam has a very specific meaning. This is not spam. – BoltClock Sep 30 '13 at 12:51
  • 1
    @Rajkumar: Sharing your knowledge is fine, but this has been asked before. Please search the site to make sure your question hasn't already been asked and answered elsewhere before you post it yourself. – BoltClock Sep 30 '13 at 12:58

3 Answers3

10

If you want the arrange the child with in the parent block just add position:relative in the parent CSS

frogatto
  • 28,539
  • 11
  • 83
  • 129
Rajkumar
  • 197
  • 3
  • 13
2

The parent block needs to be have position set to a non-static value, that is: position: absolute, position: fixed or position: relative.

The value you need depends on the layout application.

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
1
.parent {
    width: 400px;
    height: 400px;
    border: 1px solid green;
    position:relative;/*this makes all my children s position relative to me */
}

.child {
    position: absolute;/* i have an absolute position and i am relative to my parent*/
    width: 200px;
    height: 200px;
    border: 1px solid red;
    bottom: 0px;
}

Demo: http://jsfiddle.net/pGvvq/

markup:

<section class=parent>
    this makes all my children s position relative to me
    <article class=child>
        i have an absolute position and i am relative to my parent
    </article>
</section>

enter image description here

READ more http://css-tricks.com/absolute-positioning-inside-relative-positioning/

Gildas.Tambo
  • 22,173
  • 7
  • 50
  • 78