I have a div that sits at the top of the webpage, but the div should be centered horizontally.
But for some reason, the div is always sitting on the left?
Do you know how I can make a div sit in the center horizontally?
If I add "align =" center "" to the div, it will be centered, but I'm looking for a clean CSS way to make it centered:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> <title> </title> <style type="text/css"> <!-- body { text-align: center; margin: 0 auto; background-color: RGB(197, 155, 109); background-image: url("../images/bodyBk2Lite.png"); background-repeat: repeat; font-family: "Arial", "Tahoma", Serif; font-size: 17px; } p { text-align: left; } #heading { width: 100%; height: 110px; background-image: url("../images/headingBk2Lite.png"); background-repeat: repeat-y; background-color: RGB(0, 0, 0); } #headingContainer { width: 980px; height: 110px; text-align: right; background-color: red; } #headingSpacer { height: 15px; } --> </style> </head> <body> <div id="heading"> <div id="headingContainer"> <a href="index.html"><img src="images/headingImg.png" height="105px" alt="Select Recipes"/></a> </div> </div> </body> </html>
source share