简体   繁体   中英

I have an img that refuses to center and I can't figure out why?

I can't seem to center an image I have. The image is in a div surrounded by 2 other images. I have tried text-align and setting margin to auto but that doesn't seem to be working. The slider div below holding the slides should be centered but it's not.

Here's the html:

<body>
<div id = "container">
  <h1>
   Meet some of of our Members
  </h1>
  <img id="prev" src="images/rsz_back-button.png" alt="prev">
  <div id="Slider">
    <div class = "slide active">
      <div id ="slide-copy">
        <h2>
        Echo
        </h2>
      </div>
      <img src="images/rsz_a0615655ad9ed49f75bf617e2df6a47c.jpg"> </div>

  <div class = "slide">
    <div id ="slide-copy">
      <h2>
      Victor
      </h2>
    </div>
    <img src="images/rsz_dollhouse-tv-show-2.jpg"> </div>
  <div class = "slide">
    <div id ="slide-copy">
      <h2>
      Sierra
      </h2>
    </div>
    <img src="images/rsz_0000053222_20081110111439.jpg"> </div>
  <div class = "slide">
    <div id ="slide-copy">
      <h2>
      Alpha
      </h2>
    </div>
    <img  src="images/rsz_1alan-tudyk-transformers.jpg"> </div>
    </div>
  <img id="next" src="images/rsz_forward-button.png" alt="next"> </div>
</body>

and here is the css:

*{
    margin:0;
    padding:0;
}

body{
    font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size:14px;
    color:#fff;
    background:#333;
    line-height:1.6em;
}

a{
    color:#fff;
    text-decoration:none;
}

h1{
    text-align:center;
    margin-bottom:20px;
}

#container{
    text-align:center;
    width: 980px;
    margin:40px auto;
    overflow:hidden;    
}

#slider{
    margin:40px auto;
    position:relative;
    width:512px;
    height:385px;
    overflow: hidden;
    float: left;
    padding:3px;
    border: #666 solid 2px;
    border-radius:2px;
    z-index:0;

}

slider img{
    width:512px;
    height:385;
}

#prev, #next{
    float:left;
    padding-top:50px;
    z-index:1;
}

The #Slider div comes right after the floating #prev div, which pushes the #Slider to the right.

Solution: don't float the #prev . Or clear the float in the #Slider , whatever you want. (If your intention is to show the #prev to the left of the screen, give it position:absolute or something.)

By the way, there are errors in your HTML. The ID slide-copy appears twice.
And errors in your css. 385 should be 385px , and slider and #slider should both be #Slider .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM