div和img之间的空间? [英] Space between div and img?

查看:198
本文介绍了div和img之间的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

 < div id =sc> 
< h1> 1。橙色与LT; / H1>
< p>一些文字在这里< / p>
< / div>
< img class =separatorsrc =images / separator.png/>

scdiv和separatorimg之间总是有13px的差距。



两者的边距和填充都设置为0,null,空,没有任何内容。哎呀。我很生气; d

我试图弄清楚萤火虫究竟发生了什么,但它们之间的空间不属于任何东西,它不是一个保证金,而不是填充,到底是什么?



没有浮动,没有显示设置,也没有继承的边距或填充。



我的代码有什么问题?我一直试图删除HTML中的空格,但没有帮助(顺便说一句,如果我把分隔符放在scdiv之上,也有一些差距,但较小)。



谢谢。

[ADDED]



CSS样式:

  .separator {
margin:0;
padding:0;
}

#sc {
text-align:justify;
padding:0;
保证金:0;
background-image:url('images / bg.png');
background-repeat:repeat-y;
width:970px;
}


解决方案

块;到.separator图片。

  .separator {
margin:0;
padding:0;
display:block;
}

问题在于图像有时会在/下方添加一些魔法空间他们,每当我将图像元素用作 * block * 元素时,我都会遇到这个问题。


I have code like this:

        <div id="sc">  
            <h1>1. Orange</h1>
            <p>some text in here </p>                                          
        </div>
        <img class="separator" src="images/separator.png" /> 

There's ALWAYS 13px gap between the "sc" div and "separator" img.

Margins and paddings for both are set to 0, null, empty, nothing. Argh. I'm so mad ;d

I was trying to figure out what's going on with firebug but the space between them just doesn't belong to anything, it's not a margin, not a padding, what the heck?

No floats, no display settings, no inherited margins or paddings either.

What's wrong with my code? I've been trying to delete the whitespace in HTML but doesn't help (by the way if I put the separator above the "sc" div there's also some gap, but smaller).

Thanks.

[ADDED]

CSS STYLES:

.separator {
    margin: 0;
    padding: 0;
}

#sc {
    text-align: justify;
    padding: 0;
    margin: 0;
    background-image: url('images/bg.png');  
    background-repeat: repeat-y;
    width: 970px;
}

解决方案

Add display: block; to the .separator image.

.separator {
    margin: 0;
    padding: 0;
    display: block;
}

The problem is that images can sometimes add a bit of magic space up/below them, I have this issue whenever I'm working with image elements as *block* elements.

这篇关于div和img之间的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆