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

查看:215
本文介绍了是否需要诸如"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.

推荐答案

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

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

如果您将SVG内联嵌入HTML页面并将该页面作为text/html提供,则 xmlns属性不是必需的.将SVG内联嵌入HTML文档是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类型,则

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天全站免登陆