图片替换
我有一个大 div,以网站标题/徽标作为背景图像。使用 z-index 将包含网站标题的 h2 标签放在后面,这样如果用户由于某种原因无法/没有获取图像,它就会显示出来,这有什么问题吗?我知道这与标准的 [h2 元素背景] 图像替换不同。 (编辑:抱歉,也许我没有说清楚 - 我使用的是 div 背景图像而不是 IMG 标签)
I have a large div with the site header/logo as the background image. Is there anything wrong with putting a h2 tag containing the site title behind this using z-index, so that it would show if the user couldn't/didn't get the image for some reason? I know this is different to a standard [background on the h2 element] image replacement. (EDIT: Sorry maybe i'm not making it clear - i'm using a div background image not an IMG tag)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该使用 img 标签的 alt 属性,因此如果由于某种原因未加载图像,则会显示文本。
这正是 alt attr 存在的原因。
You should use the alt attribute of the img tag, so if the image isn't loaded for some reason, the text would appear.
This is exactly why the alt attr exists,.
如果可能的话,我会放弃 div 并只使用带有 id 的 h2 并为其设置背景图像。
当我可以使用其他块级元素时(如果它只有背景和文本),我会尽可能避免过多的 div。带有背景图像的 h* 仍然是标题。
If possible, I would ditch the div and just use an h2 with an id and set a background image to that.
I do that whenever possible to avoid excessive divs when I could use other block-level elements, if it only has a background and text. An h* with a background image is still a heading.
您可以简单地放置带有 alt 属性的 img 标签。这样,如果未加载图像,则会显示文本。
You can simple place img tag with alt attribute. That way if image is not loaded, text will be displayed.
Google 不喜欢您所描述的内容:
http://www. google.com/support/webmasters/bin/answer.py?answer=66353
不过,从纯粹的设计角度来看,并没有什么真正的问题,省去了一些臃肿的代码。
在尝试任何更改之前,您可能希望了解映像失败的频率。
Google doesn't like what you describe:
http://www.google.com/support/webmasters/bin/answer.py?answer=66353
However, from a pure design perspective, there is no real problem, save some bloated code.
You might want to see how often your images fail before you attempt any changes.
没关系。请注意,许多人认为网站徽标并不是真正可以放入 h* 标记中的东西,除了主页之外,而将其放入 h1 标记中是有意义的。
That's fine. Note that many feel the site logo isn't really something you'd put into an h* tag other than on the home page, when it makes sense to put it in an h1 tag.