Avatar of Modifier1000
Modifier1000
Flag for United States of America asked on

Center a DIV within another DIV with CSS

Hey all,

I have a header DIV that contains a logo DIV.  The logo DIV is all the way to the left.  How can I center the logo DIV within the header DIV?

Note:
Fluid layout
IE8
Drupal 7

Thanks in advance!
CSSHTMLContent Management

Avatar of undefined
Last Comment
Modifier1000

8/22/2022 - Mon
Kim Walker

The best way to center a div is to set it's left and right margin to "auto."
Kim Walker

By the way, that doesn't work in IE. You'll also have to give the parent div a text-align: center; in IE.
SOLUTION
Hagay Mandel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Kim Walker

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
s8web

If none of that works, you're going to have to give us some code or a link (preferably).

The norm is to assign text-align:center to the body (put text-align: left or whatever on your main container or child elements that shouldn't text align center). Then, if you declare a width, and auto on your left and right margins on any child elements that you want to center within their respective containers, they will.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Modifier1000

ASKER
Thank you.