如果从svg中省略,则viewBox属性的默认值是什么? [英] What is default value of viewBox attribute if omitted from svg?

查看:44
本文介绍了如果从svg中省略,则viewBox属性的默认值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为,如果我从svg中省略了 viewBox 属性,则假定该属性为 viewBox ="0 0 100 100" .我尝试了两个测试:

I think if I omit the viewBox attribute from svg it is assumed to be viewBox="0 0 100 100". I tried two tests:

  1. 具有viewBox属性:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-triangle" width='100' height='100'>
  <path d="M 50,5 95,97.5 5,97.5 z"/>
</svg>

  1. 没有viewBox属性

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-triangle" width='100' height='100' viewBox="0 0 100 100">
    <path d="M 50,5 95,97.5 5,97.5 z"/>
</svg>

由于两个结果相同,我认为我的猜测是正确的.请提供一些参考,以解释如果从svg中省略,则viewBox属性的默认值是什么.

As both the results are same I think my guess is correct. Please give some reference to explain What is default value of viewBox attribute if omitted from svg.

推荐答案

https://www.w3.org/TR/SVG2/coords.html#ViewBoxAttribute

省略的视图框的默认值为好像没有指定."

The default value of an omitted viewbox is "As if not specified."

这里的问题有点概念性.因此,与未指定的视图框等效的视图框为 0 0 width height ,但根本不存在未指定的视图框.一个视图框等于一个变换,如果渲染此东西,通常会将等效变换到一个视图框,然后将其添加到矩阵中.未指定的视图框根本不应用任何转换.因此,这个问题变成未指定的 transform 属性的默认值是什么.

The problem here is a bit conceptual. So the equivalent viewbox to a non-specified viewbox is 0 0 width height but an unspecified viewbox simply does not exist. A viewbox is equal to a transform and you often, if rendering this stuff, would make the equivalent transform to a viewbox and add that into your matrix. And unspecified viewbox applies no transformation at all. So this question becomes what is the default value of an unspecified transform attribute.

将SVG对象本身视为欧氏空间内的元素可能会有所帮助,就像其中的形状一样. circle 对象(尽管不在规范内)可能会有一个视图框.这意味着它将对圆的坐标系进行某种缩放,并使缩放后的视图等于圆的大小.因此,所有在空间中可以具有宽度和高度的东西都可以有一个视图框,其中一些实际上像图像对象和嵌套的SVG对象一样.没有视框,一切都是空间中实际存在的大小.对于SVG对象本身,这意味着该视图框等于该视图,它等效于在 0 0 width height 处查看该视图,因为这是该对象本身的实际大小.但是,实际上,没有视图框是没有效果的.实际上,等于 0 0 width height 的视框在转换为变换时最终将不应用任何缩放或转换值.但是,可以通过简单地省略它来实现.

It might help to think of the SVG object itself as an element within Euclidean space, just like the shapes within it. It would be possible for a circle object (though not within the spec) to have a viewbox. This would mean it would have a sort of zoom into the coordinate system of the circle and make that zoomed view equal to the size of the circle. So everything that can have a width and height within the space could have a viewbox, and a few of them actually do like image objects and nested SVG objects. Without a viewbox everything is the size that it actually exists within the space. In the case of the SVG object itself this means the viewbox is equal to the view which is equivalent to viewing it at 0 0 width height since that's the actual size of the object itself. But, really the effect of not having a viewbox is no-effect. Really a viewbox equal to 0 0 width height will end up applying no scale or translate values when turned into a transform. But, that could have been achieved by simply omitting it.

如果省略宽度和高度,则它们等于100%.也就是说,它们占据了用于查看它们的物理盒子中100%的空间.视口而不是视口.

If the width and height are omitted they are taken to be equal to 100%. Which is to say they take up 100% of the space within the physical box being used to view them. The viewport as opposed to the viewbox.

这篇关于如果从svg中省略,则viewBox属性的默认值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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