Stretch svg background without keeping aspect ratio

后端 未结 3 1407
花落未央
花落未央 2021-01-26 06:30

I want to use an svg image as background-image, I want to show the entire image (no crop) and stretch the image to 100% height and width of the container div without

相关标签:
3条回答
  • 2021-01-26 06:58
    .sample {
       height:500px;
       width:500px;
       background-image: url('sample.svg');
       background-size:cover;
       background-position:center center;
    }
    
    
    <div class="sample"></div>
    

    Just try it. I hope this will help you

    0 讨论(0)
  • 2021-01-26 06:59

    Use

    height:100% ;width:100%; background-size:contain; 
    

    to keep background aspect ratio.

    0 讨论(0)
  • 2021-01-26 07:09

    Solution:

    Open the svg file in a text editor and add this attribute:

    <svg preserveAspectRatio="none"
    
    0 讨论(0)
提交回复
热议问题