tags:

views:

70

answers:

5

I have already set the border of an image within a div to be none. I now want to center that image within its containing div. I have tried using the margin: 0 auto; but that did not work.

I am sure I am overlooking something stupid but I would like to enlist the help of the stackoverflow community so this doesn't take me an hour of staring at the screen to figure out. Thanks a lot.

<body>
    <div id="wrapper">
        <div id="banner">

            <img src="logo3.png"/>
            <!--<img src="kslf_logo.png"/>
            <img src="logo2.png" title="Katie Samson Lacrosse Festival Logo"/>-->


            <div id="social_network">
                <a href="#" target="_blank" title="Check out the Facebook Page!">Facebook</a>
            </div>

        </div>
    </div>
</body>

Here is the CSS...

#banner {
    height: 100px;
    width: 960px;
    padding-bottom: 10px;
}

#banner img {
    border: none;
    margin: 0 auto;
}
A: 

horizontal: just try

text-align:center;

:)

roman
For some reason I have not gotten the hang of posting HTML in here without it rending it as a page, sorry about that, but I think this solution only works in IE,and its not working in this case anyways, is there a cross browser compliant way to do it?
Dan
@Dan: fixed it. You have to intend every code by four spaces.
Felix Kling
A: 

Either

banner {
     height:100px;
     text-align:center;
     width:960px;
     padding-bottom:10px;}

or if the img is of specific size then

banner img {
         display:block;
         width: <somevalue>px;
         border:none;
         margin:0 auto;
         }

will work ..

Gaby
A: 

I believe it is just margin: auto; No zero needed.

Hunter
A: 

Applying text-align: center to your banner div will center its inline and inline-block children (which encompasses the img tag).

The reason why your code wasn't working is because margin: 0 auto will only center block elements.

nickelleon
+1  A: 

Try setting the image’s display property to block:

banner {
    height: 100px;
    width: 960px;
    padding-bottom: 10px;
}

banner img {
    border: none;
    display: block;
    margin: 0 auto;
}
Paul D. Waite
bingo, thanks man!
Dan
You’re most welcome, it’s a bit of a non-obvious CSS thing.
Paul D. Waite