centering a div horizontally using margin auto doesn't work when width set as a percentage, why?

Hi, I have only a div in the body. I'm trying to center the div horizontally. I added width: 60% and margin: auto, but it doesn't center it, but when i change it to width: 600px, it centers it. Why is this?
3 Replies
manzlo89
manzlo898mo ago
ok i am beginning to understand. I must be doing something wrong. I have an image inside my div. i think it shrinks when i have a percentage width. I added a border to the div and it is centered but the image is all the way on the left please explain
Jochem
Jochem8mo ago
centering the div doesn't center its contents. Basically the div is a box, and the box is set in the middle of the table, but everything in the box is still just wherever it is in the box
Want results from more Discord servers?
Add your server