2012-04-13 58 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