• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

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

0
DS928
Asked:
DS928
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
DS928Author Commented:
Thanks that worked.  It was driving me crazy!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now