【发布时间】:2023-03-04 04:23:01
【问题描述】:
HTML:
<html>
<body>
<header>
<img class="logo" />
</header>
</body>
</html>
CSS:
* {
margin:0px;
padding:0px;
border:none;
}
img.logo {
width:126px;
height:50px;
background-image:url('images/logo.png');
}
每次我尝试设置这样的 IMG 样式时,都会出现一个奇怪的边框。即使我会放置边框:0px;或边框:无;在 img.logo css 中,边框仍然存在。
【问题讨论】:
-
<img>标签需要src。 -
这不是有效的 html。 src 和 alt 是 required attributes for the image tag
-
这非常感谢。我使用 IMG 标签的原因是因为我发现它是图像最合乎逻辑的标签,它不需要关闭标签。
-
IMG 仍然是显示是内容而不是装饰(也称为演示)的图像的最合乎逻辑的标签。如果您的文档在没有图像的情况下仍然有意义,则首选 CSS。除了背景之外,您可能还想使用image replacement technique 或仅在 IMG 标记中使用徽标的透明 .png。