Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when i use position:absolute in child block it does not refer parent block? [duplicate]

Tags:

html

css

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;
}
like image 329
Rajkumar Avatar asked Sep 30 '13 12:09

Rajkumar


People also ask

What happens when the parent is display flex and child position absolute?

I´ve noticed that when positioning a child position:absolute; and its parent is display: flex what happens is that the child is like the only element in the parent. It goes out-of-flow, it does not "interact" with the other flex-childs. When positioned absolute, the flex values given to the parent AFFECT this child, on his own.

Why element are positioned absolute inside relative parent class?

Here parent class has no position so element is placed according to body. In this example parent has relative position hence element are positioned absolute inside relative parent. Show activity on this post. In a use case of needing a sticky floating "back button"/ "back to top" button.

What does position absolute mean in CSS?

When positioned absolute, the flex values given to the parent AFFECT this child, on his own. Anyone has more info about this? If you do position: absolute; on a flex-child element, it will still have flex-alignment until you give it left, right, top, bottom.

What happens if we don't specify the position of the parent element?

If we don’t specify the position of the parent element, the child <div> will be positioned relative to the page. Watch a video course CSS - The Complete Guide (incl. Flexbox, Grid & Sass) In the example above, the child <div> element is positioned at the bottom right of its parent.


1 Answers

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

like image 117
Rajkumar Avatar answered Oct 23 '22 23:10

Rajkumar