[英]css - how do I make svgs responsive?
I am getting svg
data by api call and appending it to div
in a DOM. 我通过api调用获取
svg
数据,并将其附加到DOM中的div
中。 There are 13-14 svg elements I am getting and appending it to a single div
. 我要获取13-14个svg元素,并将其附加到单个
div
。 I want to display all this svgs in a row. 我想连续显示所有这些svg。 If I give
width: 5.5%;
如果我给出
width: 5.5%;
to svg elements, all the svgs display in a row. 对于svg元素,所有svg都显示在一行中。 But when I resize window or monitor size is small, all svgs overlap each other.
但是,当我调整窗口大小或监视器大小很小时,所有svg彼此重叠。 I've created an example in jsfiddle.
我在jsfiddle中创建了一个示例。 Please find this fiddle
请找到这个小提琴
I tried with preserveAspectRatio
and viewBox
in svg but it's not working. 我尝试在svg中使用
preserveAspectRatio
和viewBox
,但无法正常工作。
Update: I've updated fiddle. 更新:我已经更新了小提琴。 In a default size of resule in jsfiddle, overlapping is visible.
在jsfiddle中,resule的默认大小是可见的。 I want it to be responsive.
我希望它能及时响应。
How do I make these svgs responsive so that it doesn't overlap each other? 如何使这些svg响应,以免彼此重叠?
For these purpose better to use img tag: 为了这些目的,最好使用img标签:
<img src="path_to_svg" style="width: 5.5%" />
And in the svg file you should add attribute such as 并且在svg文件中,您应该添加诸如
<svg width="100%" height="100%"> .... </svg>
In this case image will resize as you want. 在这种情况下,图像将根据需要调整大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.