LevelTen Web Design | Dallas, TX

shrink wrapping

Centering a CSS menu without the width (aka Shrink Wrap)

On a recent project, I ran into an issue where the main navigation needed to be centered and flexible enough to add and remove menu items through a CMS. For those of you not familiar with CSS, this creates an immediate problem: you can not center a block element without first knowing its width. The normal technique is to use auto left and right margins (margin: 0 auto), that are then calculated based off the element's width. But what happens when you don't know the width of the element?

Syndicate content