gpt4 book ai didi

html - 如何设置由 gulp-svg-sprite npm 包导入的元素 svg 背景的宽度和高度?

转载 作者:行者123 更新时间:2023-11-27 23:44:03 25 4
gpt4 key购买 nike

对于我的元素(网站),我使用了一个名为 gulp-svg-sprite 的 NPM 包,它将我所有的 SVG 图像放入一个文件 sprites.svg 中并生成 sprites.css。

在 sprites.css 中,有一些 CSS 类将它们的 background-image 属性设置为 sprite.svg 中的 svg 图像。

sprites.css:

.icon:before {
content: ' ';
vertical-align: middle;
display: inline-block;
background-image: url(/img/sprite.svg);
background-repeat: no-repeat;
background-size: 71.7em 114.4em;
}
.icon.icon-logo:before {
background-position: 0em -98.5em;
width: 42.4em;
height: 8.6em;
}

index.html 中显示所需的 SVG 图像:

<span class="icon icon-logo"></span>

问题:SVG背景图片太大

尝试解决问题 - 尝试调整它的大小,但它不起作用:

index.html:

<style>
.icon-logo:before {
width: 130px;
height: auto;
}
</style>

最佳答案

由于您的 Sprite 使用 em 单位来调整大小和定位,因此您需要更改 font-size 而不是 widthheight ,例如:

.icon-logo:before {
font-size:.8em;
}

关于html - 如何设置由 gulp-svg-sprite npm 包导入的元素 svg 背景的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56890148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com