Troubleshooting problem with image dimensions when substituting png for svg

Hey there, I've encountered an issue with svg...

Currently, I'm utilizing the modernizr script as a backup for older IE versions to switch the svg to a png extension.

The hiccup I'm facing is that I'm using widths to manage the svg sizes:

<img src="img/testing.svg" width="200px">

(although in the future I'll be setting the width in CSS for media queries to allow it to scale up and down)

Right now, I have this modernizr script in place:

if(!Modernizr.svg) {
  $('img[src*="svg"]').attr('src', function() {
      return $(this).attr('src').replace('.svg', '.png');
  });
}

Initially, it was working perfectly when I tested it in IE and it was swapping out the images without any issues. However, I did observe that if the png is "200px wide" and I've specified the svg version to be "400px wide" in my CSS - it's scaling up the png and causing blurriness.

My question is, how can I prevent the png from scaling up beyond its original size to avoid pixelation?

Or, is there a more efficient way to handle svg's and png fallbacks?

Thank you

Answer №1

It seems like you haven't shared your CSS code. Could it be possible that you have included img { max-width: 100%; } in your CSS?

If you want to stop PNG images from scaling, you can test the following code:

img[src$=".png"] {
  max-width: none;
}

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

Exploring intricate binding expressions using IF statements in ASP.NET

I am trying to create an expression for a column in my repeater, but I am not confident about the syntax. My goal is to display "No Document" if the value is equal to "DispForm.aspx", otherwise show the actual value. I attempted to combine all expression ...

A guide on dynamically using jQuery to embed an image within a hyperlink tag

I am having trouble with these HTML tags: img = <img data-dz-thumbnail="" target="_blank" alt="twitter-btn-mob.png" src="image.jpg"> a = <a href="javascript:void(0)" target="_blank"></a> My goal is to insert the image tag into the anc ...

Safari's problem with auto-filling forms

I am in the process of designing a payment form. I need to have the fields for credit card number and its expiry date set to autofill. The Chrome browser is functioning correctly, but Safari is not recognizing the expiry_date field for autofill. Below are ...

Switch the Header Image on a Page in WordPress

I am currently using the Sunrise Theme from s5themes.com and I have a question regarding the header image on individual pages. It seems that all pages are displaying the same header image as the homepage, which is not what I want. Attached below is a scre ...

Using HTML and JavaScript to choose relatives from the extended family: Uncles and Aunts

Looking for a better way to target elements in your HTML code? <div class="chunk" id=""> <div class="chunkContent"> <div class="textLeft" ></div> <div class="textRight" ></div> <div class= ...

Tips for making the background image fit perfectly within a div element

I have a calendar div that I want to customize with a background image and text. How can I achieve this? https://i.sstatic.net/hVQm2.jpg Here is my code: .calenderArrivalDiv{ margin-top: 15%; margin-bottom: 1%; ...

Utilize the existing code to prevent multiple form submissions

My current focus is on integrating a Delete Account feature into my website. If a user requests to delete their account (please note that it takes 3 days to completely delete the data) and tries to log in within this 3-day period, we need to prompt for co ...

The selenium element for the submit button is currently not responsive to interactions

Recently, I encountered some challenges with selenium, specifically the anticaptcha API. Although I managed to resolve that issue, I am currently facing a different problem. Below is my existing code: from time import sleep from selenium import webdriver f ...

What is the best approach for extracting multiple images from a URL and inserting them individually into separate divs using JavaScript?

Is there a way to elegantly display images horizontally on my website without them stacking on top of each other? I want each image to be placed side by side in a specific space for a beautiful layout. <!DOCTYPE html> <html> <head ...

Obtaining the value of a JSON object is not defined - utilizing jQuery's

It has been quite some time since I last dabbled in jQuery and I am currently facing a challenge extracting the value from the JSON returned by the server. C# approach [HttpGet] public JsonResult AjaxGetSingleNewsItem(int Id) { ...

Java: Issue with JLabel Text Alignment

At the bottom of my panel, I have a JLabel that provides text instructions to the user. When some of the text exceeded the screen width, I used tags to fix this issue. However, after implementing the code shown below, the text is no longer centered an ...

Assign a class to the "li" element containing an "a" tag with the specified href attribute

Is it possible to transform the "href" attribute of an element into a class or id like "li" for better css handling? <ul> <li><a href="#section3"><span class="fp-sr-only">due</span><span></span></a><d ...

Alternative for document.ready in AngularJS when outside of AngularJS

I am currently developing a small Chrome extension that will interact with an Angular website. I have managed to successfully detect full page reloads using $(document).ready(), but I am facing issues when it comes to detecting page changes triggered by ng ...

Major processing glitch detected in JSON and PHP data handling

I am facing an issue with my PHP page that requests data from another page using JSON. Currently, I have an AJAX call set up like this: $.ajax({ type: "POST", url: "getdata.php", cache:false, data:"lis ...

Data not maintained when page is reloaded

I am in the process of implementing a login panel on my index page. The login data will be sent via an ajax call. Upon successful verification of the username and password, I am storing the user data in a session and then reloading the index page upon ajax ...

The hierarchy of CSS in Vue components

I've developed a customized CSS framework to streamline the design process across all my internal projects. The central file is structured as shown below: @import "~normalize.css/normalize.css"; @import "_variables.scss"; @import "_mixins.scss" ...

CSS: The calc() function does not take into account the bottom padding when used in Firefox and Internet

I am encountering an issue with the calc() function in Firefox 32 and IE 11, where the bottom padding of a div is not being respected. However, this problem does not occur in Chrome and Opera. The main content section should have a fixed height while allo ...

Display the previous image when clicking on the left side of the current image within Colorbox

In Colorbox 1.6.0, the default behavior is that a click on the displayed photo will show the next available photo. I am wondering if it's possible to customize Colorbox so that when the user clicks on the left half of the current photo, it displays t ...

Unable to obtain the height of a new iframe within the DOM

Upon page load, I utilize the following code to adjust the height of the iframe based on its content's height, this aspect is functioning properly. $("iframe").height($("iframe").contents().height()); I have an iframe element on my webpage which I u ...

The custom font fails to load on a customized Material UI theme

In my React web application, I tried to implement a custom font by writing the following code: import React, { FunctionComponent } from 'react' import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles' import SofiaPro ...