2014-10-06 94 views
0

我想有一个SVG图像缩放如下:缩放SVG图像以适合家长为CSS背景

sketch

右箭头(漆成红色)应始终扩展到的高度蓝色的盒子,可以有动态的高度。

我曾尝试使用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> 

我尝试了不同的版本preserveAspectRatio和视框。

我的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看起来像

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

是否有实现这个使用SVG图像作为CSS背景的方法吗?

编辑:箭头的宽度应始终保持不变。

回答

1

要使您的红色箭头伸展到与身高匹配,请尝试preserveAspectRatio="none"

+0

奇怪,之前尝试过,但现在它工作。谢谢。 – flix 2014-10-06 12:11:32