Inline SVG breaks in Safari and Mobile Safari

后端 未结 1 924
予麋鹿
予麋鹿 2021-01-05 11:11

I recently launched a site which used a bit of inline SVG.



        
相关标签:
1条回答
  • 2021-01-05 11:31

    It turns out that Safari and Mobile Safari freak out if you omit the height and width attributes I was setting the dimensions with CSS, which worked fine in other browsers. But I had to add those attributes back in to make it behave consistently:

    <svg class="divider-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
         width="55.221px" height="58.079px" viewBox="0 0 55.221 58.079" enable-background="new 0 0 55.221 58.079" xml:space="preserve" preserveAspectRatio="xMidYMid meet">
         <path d="[...]"/>
    </svg>
    

    Notice the width and height attributes that were missing above.

    Also, it's interesting to point out that the value of preserveAspectRatio matters. I had a couple other inline SVG elements that had preserveAspectRatio="none meet" and they were unaffected by this issue.

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