Using SVG as a background image on Internet Explorer with zoom capabilities

I am having an issue with my SVG used as a background image:

<div class="bubble"></div>

Here is the CSS I am using:

.bubble
{
  background-image: url(https://beta.creasoft.cz/Images/bubble-small.svg);
  background-repeat: no-repeat;

  width: 48px;
  height: 48px;
}

When viewing in IE 11 and zoomed in (at 105% or more), it appears distorted:

https://i.stack.imgur.com/1v5nB.jpg

However, it displays correctly in Chrome. Is there a solution to fix this issue?

https://codepen.io/raptor/pen/WZoYBB

Answer №1

Internet Explorer 11 does not have the capability to scale SVG images properly when the attributes viewBox, width, and height are explicitly defined. In your situation, specifying a width and height of 48px for the image will cause scaling issues in IE11.

A simple solution is to use a container for the SVG. Start by creating a container element to hold the SVG:

<div id="container">
  <div class="bubble"></div>
</div>

Next, define the dimensions of the container and set the .bubble div or SVG's width: 100%:

#container {
  width: 48px;
  height: 48px;
}
.bubble {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-image: url('https://example.com/image.svg');
}

Make sure to remove any height and width attributes from the SVG file itself if they are present. For more information on dealing with SVGs in Internet Explorer, check out this resource.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to rearrange Bootstrap columns for extra small screens?

In my bootstrap layout, I have a row with two columns: <div class="row"> <div class="col-md-5 col-md-push-7"> Content in this column should display on the right </div> <div class="col-md-7 col-md-pull-5"> ...

Achieve an exceptional design by organizing the elements to gracefully drift from the left side to the right, seamlessly cascading from

I am currently working on a CSS and HTML layout, and I have a specific vision for how I want the layout to be displayed. It should appear from left to right and top to bottom, as shown in this image: https://i.stack.imgur.com/Q0VmR.jpg Each box within the ...

Is there any way to remove the two default aspNetHidden Divs in asp.net web forms?

After creating an empty webform page in asp.net, the generated code looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Threetier.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org ...

Tips for applying a class to two elements when a checkbox is clicked and avoiding duplicated URL strings

Issue with Checkbox Selection In my project, I have implemented two tabbed containers for grid and list view. Each container contains multiple elements called info boxes with checkbox inputs. Whenever a checkbox is checked, the background color of the res ...

Which is better for cycling through a list of items: CSS or JavaScript?

Currently, I have a navigation bar set up as an unordered list (<ul>), but some list items are not visible. I want to implement functionality where clicking arrows will move the elements left or right by hiding or showing the leftmost or rightmost it ...

Z-index behaving abnormally

I've been working on developing a website and one of the key features I'm trying to implement is a slideout menu that slides horizontally when the mouse hovers over it. To make development easier, I initially set the menu to be fully extended by ...

Implementing jQuery UI toggleClass method to seamlessly alternate between two distinct CSS classes

My goal is to toggle between two CSS classes on a selector click using Jquery UI .toggleClass(), but unfortunately, it's not producing the desired toggle effect. $(".toggle").click(function () { $(".archivePosts .columns").removeClass( "l ...

Tips for keeping a div visible while hovering over a link using only CSS

Apologies for any language errors in advance. I will do my best to explain my issue accurately: In my CSS, I have created a hidden div that is displayed none by default. When I hover over a link in the navigation bar, I change the display to block, creati ...

Ways to Toggle div Visibility for Elements with Identical Class Names on an Individual Basis

After searching for solutions on stackoverflow, I attempted to implement some answers provided by other users, but I'm still not achieving the desired outcome. In my website's about section, there are four different items. When a specific item&a ...

The header appears distorted on older versions of Internet Explorer, specifically IE 7 and IE

The website I am currently working on looks great in Chrome, Firefox, Opera, and Safari on both Mac and Windows. However, it is not displaying correctly in IE 7 & 8. The header should appear like this: But in Internet Explorer, it's showing up like t ...

What can be done to stop a header from sticking to a table and displaying horizontally scrolling content along the border?

I need to ensure that the red headers do not overlap with the blue headers' borders while scrolling horizontally. It is essential for me to have a white border on the blue headers. .container { overflow: auto; width: 200px; } table { borde ...

What is the best way to exchange configuration data among Javascript, Python, and CSS within my Django application?

How can I efficiently configure Javascript, Django templates, Python code, and CSS that all rely on the same data? For example, let's say I have a browser-side entry widget written in Javascript that interacts with an embedded Java app. Once the user ...

Using jQuery's toggleClass method to implement CSS transformations

I have a question about this situation Each time the button is clicked, jQuery toggles the class: .transition { background-color: #CBA; transform: translateX(100px) scale(0.5) rotate(180deg); } Within the <div class="container2"> And upon ...

The art of masonry is not effective

I'm having trouble getting the Masonry cascading grid layout library to work in my code. Stylesheet: .post { background: #FFF; padding: 10px; border-bottom: 3px solid #e6e6e6; width: 30.7%; margin: 10px; } Source code: <div ...

Submenu Positioning Problem Identified in Firefox Display

I am currently working on a menu design for a website and encountered an unusual issue while testing it in Firefox. In the provided fiddle link, you can view the menu layout where hovering over the information button should display a submenu directly below ...

Parsing all HTML elements using Nokogiri

I've been searching everywhere and all I could find was how to use CSS selection with Nokogiri. What I really need is to completely remove all HTML tags. For instance, this: <html> <head><title>My webpage</title></head& ...

Creating two div elements next to each other in an HTML file using Django

I'm having trouble arranging multiple divs in a single line on my website. Utilizing float isn't an option for me due to the dynamic number of divs generated by Django posts. Here is the code I am currently using: Index.html <!DOCTYPE html&g ...

Scrolling horizontally with scrollbar functionality

My goal is to create a webpage with a horizontally scrollable DIV element in the center, where the scrollbar appears only at the bottom of the DIV, not at the bottom of the entire page. I am wondering if it is possible to have a scrollbar placed at the ve ...

Display a specific tab section upon clicking using jQuery or JavaScript

Hello everyone! I am completely new to JavaScript. I have added a tab slider to my HTML with 3 categories in the tab menu: All, Creative, and Branding. How can I show a div after clicking on one of the list items? I have assigned classes to the list items ...

Styling a div element in CSS with absolute positioning and the ability to

I am looking to set specific positions and dimensions for the div elements within my HTML document. Refer to this image for reference: https://i.stack.imgur.com/ANBVm.png For each of these div elements, I want a vertical scrollbar to appear if the content ...