简体   繁体   English

调整插入了content:url()的svg图像的大小

[英]resize svg image inserted with content:url()

Ok, what I got is the following: multiple svg images with different widths/heights that are inserted into html via css. 好的,我得到的是以下内容:通过CSS将多个具有不同宽度/高度的svg图像插入到html中。 I want to scale them all to the same width but that does not work (at least not in Safari, Chrome and Firefox). 我想将它们全部缩放到相同的宽度,但这不起作用(至少在Safari,Chrome和Firefox中不起作用)。

html: 的HTML:

<h4 class="before" id="foo">Foo</h4>
<h4 class="before" id="bar">Bar</h4>
<h4 class="before" id="foobar">Foobar</h4>

css: CSS:

.before:before { width: 20px; }
#foo:before { content:url('foo.svg'); }
#bar:before { content:url('bar.svg'); }
#foobar: before { content:url('foobar.svg'); }

How could I resize those svg images so that they are displayed with 20px width each (but don't change the svg itself)? 我如何调整这些svg图像的大小,以使其以20px的宽度显示(但不要更改svg本身)?

If you know what the heights are going to be, you could set the images as the backgrounds to the pseudo-elements and declare background-size: 20px auto; 如果您知道高度将是多少,可以将图像设置为伪元素的背景,并声明background-size: 20px auto; , but you'd need to know the exact size or larger for the height of the psuedo-element itself. ,但您需要知道伪元素本身高度的确切大小或更大。

Beyond that, I wasn't able to find a way to make it work entirely just in CSS. 除此之外,我无法找到一种方法使其完全在CSS中工作。 If you have access to server-side coding, you might be able to open up the SVG file and fish out the sizes automagically. 如果您有权访问服务器端编码,则可以打开SVG文件并自动找出尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM