我可以将 HTML 嵌入到 HTML5 SVG 片段中吗? [英] Can I embed HTML into an HTML5 SVG fragment?

查看:29
本文介绍了我可以将 HTML 嵌入到 HTML5 SVG 片段中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML5 支持 标签,允许将 SVG 嵌入到 HTML 中.

HTML5 supports the <svg> tag, allowing to embed SVG into HTML.

深入一点,我可以在我的 <svg> 片段中嵌套一些 HTML 吗?例如,我想在我的 SVG 图形的某些部分放置一个经过 CSS 处理的

.

Digging a little deeper, can I nest some HTML inside my <svg> fragment? For example, I'd like to put a CSS'ed <table> in some part of my SVG graphics.

我做了一个小测试,Chrome12 不喜欢 中的 HTML

.是否有一些技术可以使其工作(例如可能是 html 容器标签?)?

I made a small test and Chrome12 didn't like the HTML <p> inside the <svg>. Is there some technique to make it work (such as maybe an html container tag?)?

推荐答案

是的,使用 元素,请参阅 这个问题 一些例子.

Yes, with the <foreignObject> element, see this question for some examples.

或者,如果您有一个 html5 文档,您还可以使用 CSS 定位和 z-index 来使部分 html 可见,您希望在 svg 顶部布局.如果您这样做,则不需要将 html 嵌套在 svg 片段中.根据我的经验,这将为您提供跨浏览器最一致的行为.

Alternatively, if you have an html5 document you can also use CSS positioning and z-index to make parts of html visible where you want laid out on top of the svg. If you do it like that you don't need to nest the html inside the svg fragment. This will give you the most consistent behaviour across browsers in my experience.

这篇关于我可以将 HTML 嵌入到 HTML5 SVG 片段中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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