Home > Web Front-end > CSS Tutorial > Why Aren't My SVGs Scaling Correctly in Internet Explorer?

Why Aren't My SVGs Scaling Correctly in Internet Explorer?

Linda Hamilton
Release: 2024-12-18 18:45:22
Original
787 people have browsed it

Why Aren't My SVGs Scaling Correctly in Internet Explorer?

SVGs not Scaling Properly in IE - has extra space

Problem: When using SVG symbols for responsiveness, the SVGs do not scale properly in Internet Explorer (IE).

Answer: IE has a bug that prevents SVGs from scaling correctly unless both the width and height are specified.

Solution:

Use a trick discovered by Nicolas Gallagher:

  1. Add a element with the same aspect ratio as the SVG to the <div> containing the SVG.
  2. Make the invisible with visibility: hidden.
  3. Position the SVG absolutely within the <div> and set its width to 100%.

Code:

<div>
Copy after login

CSS:

canvas {
    display: block;
    width: 100%;
    visibility: hidden;
}

svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}
Copy after login

Note: This trick forces IE to scale the SVG correctly by using the as a reference.

The above is the detailed content of Why Aren't My SVGs Scaling Correctly in Internet Explorer?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template