为什么 HTML 锚标记不包装可缩放的 SVG <object>? [英] Why doesn&#39;t an HTML anchor tag wrap a scalable SVG &lt;object&gt;?

查看:40
本文介绍了为什么 HTML 锚标记不包装可缩放的 SVG <object>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 SVG 文件本身中的 preserveAspectRatioviewBox 属性创建了一个可缩放的 SVG 对象:

在 HTML 中,我使用 标记引用 SVG 文件并将其包装为 :内容模型:透明,但不能有交互式内容后代."

I have created a scalable SVG object, using the preserveAspectRatio and viewBox attributes in the SVG file itself:

<svg
  …
  width="800"
  height="800"
  preserveAspectRatio="xMinYMin meet"
  viewBox="0 0 800 800"
  …

In the HTML, I reference the SVG file using the <object> tag and wrap it an <a> tag (I want to do this so that I can style it later):

<a>
  <object type="image/svg+xml" data="smiley.svg">
  </object>
</a>

I style the <object> tag with some CSS to make it 50% wide, and no wider than 100%:

object {
  max-width: 100%;
  width: 50%;
}

The problem is that the anchor tag doesn't wrap all around the object!

Any ideas anyone?

解决方案

I think @CBroe has it: SVG can be interactive content, therefore it shouldn't be wrapped by anchor element:

w3.org/TR/html5/text-level-semantics.html#the-a-element: "Content model: Transparent, but there must be no interactive content descendant."

这篇关于为什么 HTML 锚标记不包装可缩放的 SVG <object>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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