2012-04-13 82 views
0

我有一個html頁面,顯示由服務器生成的圖像列表,但我不想顯示圖像的底部2%。我的解決方案是使用overflow:隱藏在包含圖像的div上,然後在將圖像設置爲display:inline-block後爲圖像提供2%的margin-top。這對於我構建的概念頁面的簡單證明非常有用,但對於實際頁面而言並非如此。我已經上傳兩頁here溢出:隱藏不工作,因爲我期望

編輯: jsbin頁:

working

non-working

我都試過Chrome和IE9,但在這兩種瀏覽器

沒有運氣這是網頁的HTML它不適合。

<!DOCTYPE html> 
<html> 
<head> 
    <title>Test</title> 
    <link rel="stylesheet" type="text/css" href="./Test_files/ci.css"> 
</head> 
<body> 
    <div id="StockListTable" class="ListTable"> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 1" src="./Test_files/GetPreviewImage"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 2" src="./Test_files/GetPreviewImage(1)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 3" src="./Test_files/GetPreviewImage(2)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 4" src="./Test_files/GetPreviewImage(3)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 5" src="./Test_files/GetPreviewImage(4)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 6" src="./Test_files/GetPreviewImage(5)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 7" src="./Test_files/GetPreviewImage(6)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 8" src="./Test_files/GetPreviewImage(7)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 9" src="./Test_files/GetPreviewImage(8)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 10" src="./Test_files/GetPreviewImage(9)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 11" src="./Test_files/GetPreviewImage(10)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 12" src="./Test_files/GetPreviewImage(11)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 13" src="./Test_files/GetPreviewImage(12)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 14" src="./Test_files/GetPreviewImage(13)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 15" src="./Test_files/GetPreviewImage(14)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 16" src="./Test_files/GetPreviewImage(15)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 17" src="./Test_files/GetPreviewImage(16)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 18" src="./Test_files/GetPreviewImage(17)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 19" src="./Test_files/GetPreviewImage(18)"/></div> 
     <div class="PreviewCell"> <img style="border-style:none" alt="Preset 20" src="./Test_files/GetPreviewImage(19)"/></div> 
    </div> 
</body> 
</html> 

和CSS

html 
{ 
    margin:0; 
    padding:0; 
    width:100%; 
} 

body 
{ 
    margin:0; 
    padding:0; 
    font-family:sans-serif; 
    color:white; 
    background-color:black; 
    width:100%; 
    overflow-x:hidden; 
} 

.PreviewCell 
{ 
    width:12%; 
    height:20%; 
    overflow:hidden; 
    float:left; 
    padding-left:1px; 
    padding-right:1px; 
} 

.ListTable 
{ 
    margin:0; 
    width:104%; 
    height:86%; 
} 

.PreviewCell img 
{ 
    display:inline-block; 
    width:100%; 
    height:100%; 
    margin-top:2%; 
} 

它確實保證金添加到圖像的頂部,但它並不隱藏溢出,它只是使圖像的行之間有更多的空間。

下面是它工作的頁面。

<html> 
<head> 
    <style type="text/css"> 
     .testimage 
     { 
      display:inline-block; 
      width:100%; 
      height:100%; 
      margin-top:2%; 
     } 
     .container 
     { 
      width:12%; 
      height:20%; 
      overflow:hidden; 
      float:left; 
      padding-left:1px; 
      padding-right:1px; 
     } 
    </style> 
</head> 
<body bgcolor="#000000"> 
    <div class="container"> 
     <img class="testimage" src="http://192.168.0.76/ImprovCollection/GetPreviewImage?URL=sspci://StockPresets/1&Width=75&Height=76&Color=%23000000" onclick="alert('test');"/> 
    </div> 
    <div class="container"> 
     <img class="testimage" src="http://192.168.0.76/ImprovCollection/GetPreviewImage?URL=sspci://StockPresets/1&Width=75&Height=76&Color=%23000000" onclick="alert('test');"/> 
    </div> 
    <div class="container"> 
     <img class="testimage" src="http://192.168.0.76/ImprovCollection/GetPreviewImage?URL=sspci://StockPresets/1&Width=75&Height=76&Color=%23000000" onclick="alert('test');"/> 
    </div> 
    <div class="container"> 
     <img class="testimage" src="http://192.168.0.76/ImprovCollection/GetPreviewImage?URL=sspci://StockPresets/1&Width=75&Height=76&Color=%23000000" onclick="alert('test');"/> 
    </div> 
</body> 
</html> 

我很困惑,爲什麼這是行不通的,我甚至驗證了頁面(我從來沒有這樣做),並檢出。

任何幫助將是太棒了。

+1

與其提供項目的'.zip',最好是在jsbin.com上在線創建一個快速演示。 – Sampson 2012-04-13 18:12:50

+0

我們對發生的事情感到困惑??使用jsfiffle(http://jsfiddle.net)更有效地描述您的問題。 – 2012-04-13 18:19:10

+0

@Jonathan我已經添加了jsbin演示的鏈接。這是一個非常好的工具,謝謝 – nick 2012-04-13 18:30:11

回答

2

如果你想下邊距刪除,你可以使用一個negative margin cropping technique.

.PreviewCell img 
{ 
display:inline-block; 
width:100%; 
height:100%; 
margin-bottom: -4%; 
} 

如果你正在尋找去除白線的最小百分比與瀏覽器的寬度變化。

+0

這就是我最終的結果,儘管我不完全確定爲什麼它不能使用積極的頂部邊緣。 – nick 2012-04-14 05:53:14