CS 601 – Centering Body

While doing the table to divs exercise, I was having trouble centering the body text. I finally managed to do it using the following css code:

#main {
width: 800px;
margin: auto;
}

This didn’t seem to work, and I couldn’t figure out why. It turns out I missed the size unit (px) on the width, which caused it to be ignored. So, as a note for the future, ensure all lengths have a unit. (I might even use it for 0 lengths despite the fact that it’s not needed. That way, if I ever change it later, I won’t miss it again.) Luckily, the validator will catch this (as I just found out by validating an old version of the css file). When I have problems that I can’t figure out, I should validate it as a debeugging check.

Leave a Reply

Your email address will not be published.