css - 调整背景 svg 的大小

标签 css html svg

我想在背景图像中使用调整本地 svg 的大小,但设置 width=100% 和 height=100% 不起作用。 我什至将 svg 图像调整为 1425 像素 x 835 像素

This is the output when using svg image as background

我的 CSS 代码:-

#main-page #products-section {
text-align: center;
background-image: url('/assets/images/product_background_img.svg');
background-size: 100% 100%;
background-repeat: no-repeat;
}

当使用 background-image: url('/assets/images/product_background_img.png');

输出是:This is the output when using png image as background

它在 .png 图像上运行良好,但我想在 svg 文件上实现同样的效果。由于 png 图像的文件更大,它会使我的网页变重。

最佳答案

您可以尝试使用 height: 100vhwidth: 100vw 而不是 height: 100%width: 100%.

关于css - 调整背景 svg 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51357848/

相关文章:

php -\n\t\t\t\t\在php中的含义和用途是什么

html - SVG <use> 在 Firefox 和 IE 中表现奇怪

html - 可以将 <div> 放在 <a> 中吗

css - Magento 布局和位置

html - 如何在伪元素前后的CSS中显示欧元符号

html - 如何防止浏览器窗口调整大小时 block 偏移发生 1-2px 的变化

svg - 剪切的 SVG 多边形接收鼠标事件

javascript - 当存在相邻元素时,d3 svg 缩放不起作用

css - 如果可以使用严格的 CSS 重新创建图像,那么该图像还有用吗?

javascript - Z-index 透明图像