2012-04-03 56 views
1

我想我的中心圖像,但沒有我曾嘗試作品:(圖片不會居中

這裏是CSS:

#slideshow { 
    position:relative; 
    height:200px; 
} 

#slideshow IMG { 
    position:absolute; 
    top:0; 
    left:0; 
    z-index:8; 
    opacity:0.0; 
} 

#slideshow IMG.active { 
    z-index:10; 
    opacity:1.0; 
} 

#slideshow IMG.last-active { 
    z-index:9; 
} 
#slideshow, #slideshow2, #slideshow3 { 
    overflow:hidden; 
    float:left; 
    width:267px; 
} 
.contentImages{ 
    border:1px solid #CCC; 
    padding:10px; 
    margin:20px auto 0; 
    position:relative; 
    width:804px; 
    overflow:hidden; 
} 

和HTML:

<div class="contentImages"> 
    <div id="slideshow"> 
     <img src="upload/<?php echo $array['image'] ?>" height="200" class="active" /> 
     <img src="upload/<?php echo $array['image2'] ?>" height="200" /> 
     <img src="upload/<?php echo $array['image3'] ?>" height="200" /> 
    </div> 
</div> 

我試過text-align,valign,margin 0 auto有相對位置和寬度,沒有任何東西:(任何人有任何想法?

+0

如果你保持'的位置是:絕對的;'那裏不會有任何效果。 – hjpotter92 2012-04-03 17:44:46

+0

正確!位置:絕對的;刪除繼承的佈局規則。 – 2012-04-03 17:45:29

+0

使用好老'

',它總是工作並且跨瀏覽器! :-)其他人會殺了我,但一堆css過度殺傷,而不是一個小的,簡單的過時的':-) ....這是不值得的,除非你愛花幾個小時讓你的工作代碼也有效:-) – TMS 2012-04-03 17:49:37

回答

0

我不知道你的佈局細節,但容器上的text-align: center;應該工作,除非圖像是絕對定位的。試試這個代替規則#slideshow#slideshow IMG

#slideshow { 
    position:relative; 
    height:200px; 
    text-align: center; 
} 

#slideshow img { 
    z-index:8; 
    opacity:0.0; 
} 
+0

你可以在http://www.willruppelglass.com/看到佈局(底部圖片) – user979331 2012-04-03 17:50:01