Doesn't SVG support auto width and height for

2019-06-18 16:02发布

In HTML image element can be created without dimensions specified. It will have intrinsic width and height:

<img src="me.jpg" alt="">

However, in SVG image without dimension attributes will have 0×0 size, to prevent this width and height must be specified (as in this example):

<image xlink:href="me.jpg" width="64" height="64" />

Can SVG image be forced to take it's original width and height (without adding corresponding attributes, of course)? I'm curios about inline SVG inside HTML, if it matters.

标签: image svg
1条回答
Lonely孤独者°
2楼-- · 2019-06-18 16:21

The SVG 1.1 specification requires the width and height attributes for the <image> element. Most browsers today implement that, so the answer is not yet. Leaving the attributes off means a default value of 0 is used, which has the effect of making the image invisible.

However, autosizing of images is being added to SVG2, see https://svgwg.org/svg2-draft/embedded.html#ImageElement.

SVG 2 Requirement: Support auto-sized images.
Resolution: We will allow auto-sized images in SVG 2.

This hopefully means that you'll be able to do what you want in a not too distant future.

查看更多
登录 后发表回答