简体   繁体   English

我的内嵌图像下方的额外间距

[英]Extra spacing below my in-line images

Background 背景

I am creating a video gallery using the ShadowBox jQuery plugin. 我正在使用ShadowBox jQuery插件创建一个视频库。 To do this, I am creating rows of inline images using display:inline-block . 为此,我使用display:inline-block创建内联图像行。 The user will be able to upload a video as well as thumbnail images to accompany the video. 用户将能够上传视频以及缩略图图像以伴随视频。 The thumbnail's max size is 240x160 pixels. 缩略图的最大尺寸为240x160像素。

What I want to do is have a black border around each gallery thumbnail "slot" with the user's uploaded thumbnail residing inside of that "slot", so if the user uploads a 240x160 thumbnail, the thumbnail will fill up the "slot" completely, and if they upload a smaller image, the thumbnail will still be in the "slot" with some extra spacing around it. 我想要做的是在每个图库缩略图“插槽”周围有一个黑色边框,用户上传的缩略图位于该“插槽”内,因此如果用户上传240x160缩略图,缩略图将完全填满“插槽”,如果他们上传较小的图像,缩略图仍然会在“插槽”中,并且周围有一些额外的间距。

Here's an example of where I am right now: http://jsfiddle.net/shaunp/HvZ5p/ 以下是我现在所处位置的示例: http//jsfiddle.net/shaunp/HvZ5p/

The problem is that there is extra spacing below my thumbnails and I'm not sure why. 问题是我的缩略图下面有额外的间距,我不知道为什么。 If you inspect the code you will see that there is an extra 5 pixels lurking below the image and I'm not sure where it's coming from. 如果你检查代码,你会发现图像下方有一个额外的5个像素,我不知道它来自哪里。 The grey part below the image should be directly BEHIND the image so that in the case the user uploads a smaller thumbnail, there will be grey-background space around it, but for some reason it is too tall. 图像下方的灰色部分应该直接在图像背后,以便在用户上传较小的缩略图的情况下,周围会有灰色背景空间,但由于某种原因它太高了。 Any suggestions? 有什么建议么?

HTML HTML

<div class="inline">
    <div class="bg-thumb">
        <div class="cell-thumb">
            <a href="#" rev="#nvcCaption#" class="shadow">
                <img src="http://farm9.staticflickr.com/8330/8135703920_f2302b8415_m.jpg" class="thumbImg" alt="Thumb" />
            </a>
        </div>
    </div>
    <div class="vcCaption">Caption</div>
</div>
<div class="inline">
    <div class="bg-thumb">
        <div class="cell-thumb">
            <a href="#" rev="#nvcCaption#" class="shadow">
                <img src="http://farm9.staticflickr.com/8330/8135703920_f2302b8415_m.jpg" class="thumbImg" alt="Thumb" />
            </a>
        </div>
    </div>
    <div class="vcCaption">Caption</div>
</div>

CSS CSS

body {
    overflow:hidden;
    margin:0 50px 0 50px;
}
.vcCaption {
    text-align:center;
    font-family:"HelveticaNeue-Light","Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size:14px;
    color:#000;
    margin-bottom:5px;
}
.inline {
    display:inline-block;   
}
.bg-thumb {
    width:250px;
    height:170px;   
}
.bg-thumb {
    text-align:center;
    display:table;
    margin-bottom:5px;
}
.cell-thumb {
    display:table-cell;
    vertical-align:middle;
    border:5px solid #000;
    background-color:#7f7f7f;
}
.thumbImg {
    max-width:240px;
    max-height:160px;
}

Add vertical-align:top to your thumbnails: 在您的缩略图中添加vertical-align:top

.thumbImg {
    max-width:240px;
    max-height:160px;
    vertical-align:top;
}

jsFiddle example jsFiddle例子

The default value of vertical-align is baseline , but for your needs you'll want the images to align to the top. vertical-align的默认值是baseline ,但是根据您的需要,您需要将图像对齐到顶部。

Another option would be to set the font size to zero on the containing div like: 另一种选择是在包含div上将字体大小设置为零,如:

.cell-thumb {
    display:table-cell;
    vertical-align:middle;
    border:5px solid #000;
    background-color:#7f7f7f;
    font-size:0;
}

jsFiddle example jsFiddle例子

Adding vertical-align: middle; 添加vertical-align: middle; to your image will solve that. 你的形象将解决这个问题。

.thumbImg {
    vertical-align: middle;
    max-width:240px;
    max-height:160px;
}

the anchor tag is by default an inline element which gives it extra spacing, set it to a block element and give it some width and height! 默认情况下,锚标签是一个内联元素,它赋予它额外的间距,将其设置为块元素并赋予它一些宽度和高度!

.cell-thumb a {
    display: block;
    width: 240px;
    height: 160px;
}

Images will by default display as inline-block ( http://dev.w3.org/html5/markup/img.html#img-display ) meaning that they will sits on an inline level block - or text line if you prefer. 默认情况下,图像将显示为inline-blockhttp://dev.w3.org/html5/markup/img.html#img-display ),这意味着它们将位于内联级别块 - 或文本行(如果您愿意)。

Either set the font-size and/or line-height to 0 or in this case simply set the image to display at block level ( display: block; ). font-size和/或line-height0或者在这种情况下,只需将图像设置为在块级别display: block;display: block; )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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