简体   繁体   English

缩放SVG图像以适合父级作为CSS背景

[英]Scale svg image to fit parent as css background

I want to have an svg image to be scaled as follows: 我想要一个svg图像,其缩放比例如下:

草图

The right arrow (painted in red) should always scale to the height of the blue box, which can have dynamic height. 右箭头(用红色绘制)应始终缩放到蓝色框的高度,该框可以具有动态高度。

I have tried implementing it using an svg image: 我尝试使用svg映像实施它:

   <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
   <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
      "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
      viewBox="0 0 50 100" preserveAspectRatio="xMidYMid meet">
      <polygon points="0,0 50,50 0,100" style="fill:white" />
    </svg>

I tried different versions of preserveAspectRatio and viewBox. 我尝试了不同版本的preserveAspectRatio和viewBox。

My css implementation is like 我的CSS实现就像

#before-main section header.section-header .header-arrow {
    position:absolute;
    right:0;
    height:100%;
    width:4.1%;
    background:url("../img/headlineArrow_bg.svg") no-repeat right center;
    background-size:100% 100%;
}

HTML looks like HTML看起来像

<header class="section-header">
    <div class="header-arrow">
    </div>
</header>

Is there a way to implement this using the svg image as css background? 有没有一种方法可以使用svg图像作为CSS背景来实现呢?

Edit: Width of The arrow should always stay the same. 编辑:箭头的宽度应始终保持不变。

要使红色箭头拉伸以匹配高度,请尝试preserveAspectRatio="none"

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

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