Aside from setting margin: 0 auto;
, you must also make changes to the #navigation
by removing position: absolute;
and left: 260px;
Additionally, it's important to note that you are giving a larger size to the menu #navigation
and a smaller size to the header containing it with the .center
class.
Solution:
header .center {
background: url("https://dl.dropbox.com/sh/1mp20mw7izrycq2/fUbLOQUbN0/pingdom-theme/images/header-center.png") no-repeat;
width: 510px;
height: 100%;
margin: 0 auto;
}
#navigation {
width: 705px;
height: 50px;
overflow: visible;
}
Your previous code was not functioning correctly because you were only using margin: auto
. Although this should technically work as it assigns margins of auto
to all sides, the position properties in your #navigation
were preventing proper centering.
Remember:
When declaring properties like margin
, padding
, or border
, you have two shorthand options to apply them to all sides efficiently.
margin: 0 auto
means: Margin top and bottom will be 0, while left and right will be set to auto.