Why Aren't My SVGs Scaling Correctly in Internet Explorer?
Dec 18, 2024 pm 06:45 PMSVGs 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:
- Add a <canvas> element with the same aspect ratio as the SVG to the <div> containing the SVG.
- Make the <canvas> invisible with visibility: hidden.
- Position the SVG absolutely within the <div> and set its width to 100%.
Code:
<div>
CSS:
canvas { display: block; width: 100%; visibility: hidden; } svg { position: absolute; top: 0; left: 0; width: 100%; }
Note: This trick forces IE to scale the SVG correctly by using the <canvas> 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Adding Box Shadows to WordPress Blocks and Elements

Create a JavaScript Contact Form With the Smart Forms Framework

Create an Inline Text Editor With the contentEditable Attribute

Making Your First Custom Svelte Transition

Comparing the 5 Best PHP Form Builders (And 3 Free Scripts)

File Upload With Multer in Node.js and Express

Best CSS Animations and Effects on CodeCanyon 2025 (Paid Free)
