CSS absolute position property

Hi there.
How are you doing?
I’m confused a little bit about css absolute positon property.
To see the effect of absolute property of an element I should make it’s parent relative. Why I need to do that? Why I can’t simply just use absolute property?

I searched online they’re not proper to me.

I’d like a little help here.

Have a great day.

1 Like

Can you tell me why you think this is needed? Did you read it somewhere? Where?

2 Likes

I didn’t read it. It just came to my mind. Out of curiosity I asked.
Thank you for the quick reply.

1 Like

Generally you should try to learn by reading a reference that can be trusted. But you say you didn’t read this piece of information anywhere, you just thought of it? And you are looking for someone to tell you it is correct? This is very confusing.

As far as I know (for eg. by reading this ref: https://developer.mozilla.org/en-US/docs/Web/CSS/position) you don’t need to make the parent element relative in order to use the absolute property on a child element and see its effect.

Perhaps you should just try to use it and if you are struggling, post your code and/or a link to your codepen so we can see what you tried that didn’t work for you and advise you further.

1 Like

I refered to the link you mentioned.
And I didn’t understand properly the difference between relative and absolute.
I watched a video on YouTube and in that it was mentioned to see a child’s absolute property in effect make it’s parent relative or else it [ browser ] would consider the whole window as the child’s parent.

There I didn’t understand why would it do that?

I was going through freecodecamp curriculum there I was stuck.
I remember to refer.
Yes, I’m asking to tell me whether I asked is correct?

Thank you for your time. I’m new and trying to adjust. Sorry for the trouble.

1 Like

Relative positioning is a way to move something away from its normal location.
For eg. if you have an element that is normally located in the middle of the page and you want to move it up a bit or down a bit, you use relative. It’s a way for people to offset elements from their normal location.

Absolute positioning is a way to essentially tell the browser exactly where you want your element to be. exactly. It will always be in that place no matter what happens.

code examples here. You can play with them to understand further:
https://www.w3schools.com/css/tryit.asp?filename=trycss_position_absolute

2 Likes

Totally understood.
:slight_smile:

This clarified everything.

If you really want to understand though, code something. It will help you crystalize the ideas so they don’t confuse you down the road again.

1 Like