height: auto on SVG not working

后端 未结 2 443
感情败类
感情败类 2020-12-31 02:35

I am trying to use an SVG sprite sheet using the \"symbol\" method detailed here.

http://css-tricks.com/svg-sprites-use-better-icon-fonts/

My HTML is very si

相关标签:
2条回答
  • 2020-12-31 02:53

    In older versions of Safari, as well as a few old Android browsers, setting the viewbox and the width was not enough.

    In my instance, I need to apply height:100%; as well as a width.

    0 讨论(0)
  • 2020-12-31 02:54

    DEMO

    You need to define a viewBox on each element that you link to. because there can be different elements in one SVG document.

    So remove the viewBox from the element you link to. Add a viewBox to the place you're linking from.

    I suggest you add the viewBox to a svg element:

    <svg class="test" viewBox="0 0 25 25">
        <use xlink:href="/images/iconSprite.svg#clock"/>
    </svg>
    

    Now you can scale it:

    If you define the css width:

    .test {
        width: 50px;
    }
    

    It will display as long as it fits on height or width.

    So if you want a responsive design you can simply scale it by % length
    .test { width:30%; }

    SCALE SVG A really good article about scaling svg from CSS-tricks :)

    0 讨论(0)
提交回复
热议问题