How to center an element in css

I want to center an element without writing any code for the parent.
I know
display:flex;
btw.
But it is for the parent not for the particular element.
THANKS

i suggest you look into https://www.w3schools.com/css/css_align.asp 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!
Thanks!

just set display:flex;

Thanks a lot, this is what I wanted, thanks

1 Like