是否需要诸如“xmlns"和“version"之类的 SVG 参数? [英] Are SVG parameters such as 'xmlns' and 'version' needed?

查看:38
本文介绍了是否需要诸如“xmlns"和“version"之类的 SVG 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我在互联网上看到的大约一半的 svg 示例中,代码包含在简单的 <svg></svg> 标签中.

In about half of the svg examples I see on the internet, the code is wrapped in plain simple <svg></svg> tags.

在另一半中,svg 标签有很多像这样的复杂属性:

In the other half, the svg tags have lots of complicated attributes like this:

<svg 
  xmlns="http://www.w3.org/2000/svg" 
  version="1.1" 
  xmlns:xlink="http://www.w3.org/1999/xlink"> 

我的问题是:可以使用简单的 svg 标签吗?我试过玩弄复杂的,如果我不包括它们,我最后一切正常.

My question is: is it ok to use the simple svg tags? I've tried playing around with the complicated ones, and everything works fine at my end if I don't include them.

推荐答案

所有用户代理(浏览器)都忽略版本属性,因此您可以随时删除它.

All user agents (browsers) ignore the version attribute, so you can always drop that.

如果您将 SVG 内联嵌入 HTML 页面并将该页面作为 text/html 提供,则 xmlns 属性不是必需的.在 HTML 文档中内嵌 SVG 是一项相当新的创新,它是 HTML5 的一部分.

If you embed your SVG inline in a HTML page and serve that page as text/html then xmlns attributes are not required. Embedding SVG inline in HTML documents is a fairly recent innovation that came along as part of HTML5.

但是,如果您将页面作为 image/svg+xml 或 application/xhtml+xml 或任何其他导致用户代理使用 XML 解析器的 MIME 类型提供,则 xmlns 属性必需的.直到最近,这是唯一的做事方式,所以有很多这样的内容.

If however you serve your page as image/svg+xml or application/xhtml+xml or any other MIME type that causes the user agent to use an XML parser then the xmlns attributes are required. This was the only way to do things until recently so there is a lot of content served like this.

这篇关于是否需要诸如“xmlns"和“version"之类的 SVG 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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