HTML严格& CSS:我如何弥合差距? [英] HTML Strict & CSS: How do I close the gap?

查看:106
本文介绍了HTML严格& CSS:我如何弥合差距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下网页中,图片和div之间有几个像素的间隙。 (我已在Firefox 3和Safari 4中测试过。)

In the following web page, there is a gap of a few pixels between the image and the div. (I've tested in Firefox 3 and Safari 4.)

如何弥补差距?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
    <title>Test Page</title>
    <style type="text/css" media="screen">
        body
        {
            background-color: black;
        }

        img 
        {
            width: 250px; 
            height: 70px; 
            border: 0; 
            margin: 0; 
            padding: 0;
        }

        div
        {
            background-color: white; 
            border: 0; 
            margin: 0; 
            padding: 0;
        }

    </style>
</head>

<body>

<img alt="Stack Overflow Logo" src="http://is.gd/lEfE">
<div>text</div>

</body>
</html>


推荐答案

图片是内嵌元素,文本行的基线。间隙是基线和文本行底部之间的距离(即,用于悬挂诸如g和j的字符的基线下面所需的空间)。

The image is an inline element, so it's placed on the base line of a text line. The gap is the distance between the base line and the bottom of the text line (I.e. the space needed below the base line for hanging characters like "g" and "j").

将图片设为块元素,间隔消失:

Make the image a block element, and the gap goes away:

 display: block;

这篇关于HTML严格&amp; CSS:我如何弥合差距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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