图像标题翻转的语义标记?

发布于 2024-11-18 10:04:43 字数 993 浏览 3 评论 0原文

我正在为我的网站制作图像标题翻转效果,并且已经基本完成。我使用 CSS 和 jQuery 的组合。

它看起来像这样...

在此处输入图像描述

效果很好。每当您将鼠标悬停在图像上时,标题就会出现在图像的左侧。

但是,我在 Visual Studio 中收到警告,根据 XHTML 1.0 Transitional,无法将 h2 标记放置在标签内部。

这是我正在使用的标记...

<ul>
    <li>
        <a href="/controls/27/saturation-rollover-effect">
            <label class="info">
                <h2>Saturation Rollover Effect</h2>
                <p>Product description here...</p>
            </label>
            <img src="/thumbnail/small/27-saturation-rollover-effect.jpg" alt="Saturation Rollover Effect" />
        </a>
    </li>
</ul>

我还尝试使用 span 代替 label,并且收到相同的消息。我还尝试过 div,但 div 不应该位于 a 标记内。

我更愿意将所有这些内容保留在链接内,就像我拥有它一样,可以从文本中获得搜索引擎优化的好处。但我也希望能够兼容 XHTML Transitional,并且同时具有语义/意义。有什么想法吗?

I'm working on an image caption rollover effect for my site and it's pretty much done. I'm using a combination of CSS and jQuery.

It looks something like this...

enter image description here

It works well. The caption appears to the left of the image whenever you mouseover the image.

However, I'm getting a warning in Visual Studio that an h2 tag cannot be placed inside of a label according to XHTML 1.0 Transitional.

Here's the markup I'm working with...

<ul>
    <li>
        <a href="/controls/27/saturation-rollover-effect">
            <label class="info">
                <h2>Saturation Rollover Effect</h2>
                <p>Product description here...</p>
            </label>
            <img src="/thumbnail/small/27-saturation-rollover-effect.jpg" alt="Saturation Rollover Effect" />
        </a>
    </li>
</ul>

I've also tried a span in place of the label, and I get the same message. I've also tried a div, but div's are not supposed to be inside of the a tag.

I'd prefer to keep all of this inside of the link like I have it to get the SEO benefit from the text. But I'd also like to be XHTML Transitional compliant, and semantic/meaningful at the same time. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不语却知心 2024-11-25 10:04:43

标签 用于表单元素,而不是图像。

h2 是可以接受的,尽管您通常希望将其用于较大的内容块。

HTML5 引入了 figurefigcaption,它们可能适合这种情况:

http://html5doctor.com/the-figure-figcaption-elements/

至于将其包装在 a 标记中,这可能没有意义,除非href 解析为没有 JavaScript 的有效 URI。由于它是滚动效果,因此单击链接不适用。

A label is for form elements--not images.

An h2 is acceptable, though you'd typically want to use that for larger blocks of content usually.

HTML5 has introduced figure and figcaption which might be appropriate in this situation:

http://html5doctor.com/the-figure-figcaption-elements/

As for wrapping it in an a tag, that probably doesn't make sense unless the href resolves to a valid URI sans JavaScript. Since it's a roll-over effect, clicking a link woudldn't be applicable.

浅忆流年 2024-11-25 10:04:43

经过一番重新思考后,我想出了一些可行且有意义的东西,我想......

<ul>
    <li>
        <div class="info">
            <h2><a href="/controls/27/saturation-rollover-effect">Saturation Rollover Effect</a></h2>
            <p>Product description here...</p>
        </div>
        <a href="/controls/27/saturation-rollover-effect"><img src="/thumbnail/small/27-saturation-rollover-effect.jpg" alt="Saturation Rollover Effect" /></a>
    </li>
</ul>

我必须将标题从图像周围的链接中分离出来。然后我在产品标题周围添加了一个链接(无论如何,这可能对 SEO 更有用)。这是有效的 XHTML。感谢 David Thomas 和 BoltClock 的评论。

更新:

这现在在我的网站上上线了。它在 IE8 中可以正常工作,但不如在 IE9、Chrome 或 Firefox 中那么漂亮。然后我可能会将缩略图设为灰度以获得更清晰的外观。总的来说,它似乎工作得很好... http://www.silverlightxap.com/

After a little rethink I came up with something that works and makes sense, I think...

<ul>
    <li>
        <div class="info">
            <h2><a href="/controls/27/saturation-rollover-effect">Saturation Rollover Effect</a></h2>
            <p>Product description here...</p>
        </div>
        <a href="/controls/27/saturation-rollover-effect"><img src="/thumbnail/small/27-saturation-rollover-effect.jpg" alt="Saturation Rollover Effect" /></a>
    </li>
</ul>

I had to break the caption away from the link around the image. Then I added a link around the title of the product (which is probably more useful for SEO anyway). And this is valid XHTML. Thanks to David Thomas and BoltClock for the comments.

UPDATE:

This is live on my site now. It's functional in IE8, but not quite as pretty as it is in IE9, Chrome, or Firefox. And then I might make the thumbnails grayscale for a cleaner look. Overall it seems to work pretty well though... http://www.silverlightxap.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文