How to center an element in css

I want to center an element without writing any code for the parent.
I know
But it is for the parent not for the particular element.

i suggest you look into as this topic is not as simple as it may seem, but the short answer, which can work in majority of cases is set the element margin to auto

Thanks a lot. Okay .

you can use
justify-content : center;

Does it apply to the parent of to the element itself

But it didn’t work for me.

Didn’t work for me :frowning:

justify-content can be applied to the child, when its parent have display: flex. Maybe if you give us a glimpse of your code with css for the parent and child, we can decide on whats the best solution for you

Oh! Okay!
Now I get it!

just set display:flex;

Thanks a lot, this is what I wanted, thanks

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.