Centering An Image

I am trying to center an image but it is refusing to do so.
 <div id="container" class="space">
    <div id="overlay">
         <nav>  
        <ul class="menu">
            <li class="current"><a href="index.html">Home</a></li>
            <li><a href="breeding.html">Services</a></li>
            <li><a href="sale.html">Work</a></li>
            <li><a href="events.html">Rental</a></li>
            <li><a href="gallery.html">About</a></li>
            <li><a href="gallery.html">Press</a></li>
            <li><a href="contacts.html">Contacts</a></li>
        </ul>
        <div class="clear"></div>
     </nav>
    </div>
    <div id="base">
      <img src="images/BarTop.jpg"/> 
    </div>
    <img src="images/Glasses.jpg" class="center"/>
  </div>

Open in new window


Any reason why this is not happening?
The CSS
.space {
	padding-bottom:300px;
}

img.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

Open in new window

DS928Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

duncanb7Commented:
div tag need to have  fixed width for center, you need to chose the width you want , and no need to  center img tag

.space {
width:1000px;
margin:0 auto;
}

if not work becoz of different browser , try
.space {
width:1000px;
margin:0 auto;
}
#base {
width:500px;
margin:0 auto;
}
Duncan
0
COBOLdinosaurCommented:
Without an explicit width a block element defaults to 100% and margins right and left have no effect.  Simple add a width to the rule img.center and it will work fine.

Cd&
0
DS928Author Commented:
Mercy.  I added a set width and now its on the right!  I attached the file for clarity.  Just trying to get the image centered not the menu bar at the top.  I tried this as well.
<div style="width:1200px"><img src="images/Glasses.jpg" class="center"/></div>

Open in new window

Untitled-1.html
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

COBOLdinosaurCommented:
The width has to be on the image, not the div.

IThe code show all kinds of other CSS and scripting that also interferes with CSS so there is no reliable way of determining what affects the the positioning without a link so we can do diagnostics.  Even with that we may find that the problem is an override in scripting, that you will have to find by digging around in the plugin code.

Cd&
0
DS928Author Commented:
Here is the link.
http://www.davidschure.com/Untitled-1.html
in the meantime I will continue digging.
0
COBOLdinosaurCommented:
The markup is broken... 42 validation errors.

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.davidschure.com%2FUntitled-1.html&charset=%28detect+automatically%29&doctype=Inline&group=0

You have an xhtml doctype, but you are trying to use HTML5 tags, plus it looks like there are structural errors with extra tag endings, and I think the slider is probably the source of most of the warnings,

You need to cleanup the code.  It can be XHTML or it can be HTML5, but it cannot be both; because they have mutually exclusive structural specifications.

Cd&
0
DS928Author Commented:

Open in new window

OK I striped down the page.

http://www.davidschure.com/Untitled-1%20-%20Copy.html

Does this maker it easier?
Untitled-1---Copy.html
0
myderrickCommented:
Note that the in the image, the man is not in the center. There is a large space on the right, The image looks centered but the man is not in the center in the image itself.

If you want the image centered on top of the horses, the  parent <div> should have elements with width, and margin: 0 auto. Example:

#container {width: xxx; margin: 0 auto;}

Good luck.
MD



Good luck.

MD
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DS928Author Commented:
Thanks that worked.  It was driving me crazy!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.