Categories
CSS

How to position absolute but relative to parent with CSS?

Spread the love

To position absolute but relative to parent with CSS, we set the position property.

For instance, we write

#father {
  position: relative;
}

#son1 {
  position: absolute;
  top: 100%;
}

to set the parent element to have relative position with position: relative;.

Then we set the child to have absolute position with position: absolute;, which will position it relative to the parent.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *