How to Create a Responsive and Transparent Background Image for a Div in Internet Explorer 8

Reasons why this question is not a duplicate: Despite reading previous solutions such as IE 8: background-size fix and How do I make background-size work in IE?, they did not work for my specific case. This could be due to the fact that I am using bootstrap. My goal is to create a responsive and transparent background for a div.

Currently, I am utilizing bootstrap 3.3.6 and I am encountering issues with properly displaying the following code in IE8:

<head>
    <title>Bootstrap Example</title>    
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="libs/bootstrap-3.3.6-dist/css/bootstrap.min.css">
    <script src="libs/jquery-1.11.2.min.js"></script>
    <script src="libs/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="libs/myCSS/font-face.css">    
    <script src="libs/respond.js"></script>
    <script src="libs/html5shiv.js.js"></script>
    ...
</head>

<body>
    ...
    <div class="col-md-6">
        <div class="row">
            <div class="col-md-6 text-center center">
                <div class="row">
                    <div class="left-finger-picker img-responsive"> //this is my background image
    ...
</body>

The CSS for "left-finger-picker" is as follows:

.left-finger-picker {
    width: 200px;
    height: 210px;
    position : relative;
    background-size: cover;     
    background-image : url("../myPics/leftHand.png");
    background-repeat: no-repeat;
    background-size: contain;

    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../myPics/leftHand.png', sizingMethod='scale');
    -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='../myPics/leftHand.png', sizingMethod='scale')";

}

The CSS for "right-finger-picker" is similar to "left-finger-picker" except for the image source.

Desired output in Chrome, Firefox, and IE11:

https://i.sstatic.net/7LtCV.png

Current output in IE8:

https://i.sstatic.net/423CW.png

Another issue I am facing is that the background of the div appears white instead of transparent, even though the original images are transparent in PNG format.

Answer №1

For optimal compatibility with IE8, my suggestion would be to utilize img tags with specified width and height settings through css.

If you require IE8 support, consider referencing this w3c resource, which mentions that the background-size attribute is exclusively supported starting from IE version 9.

Answer №2

Sadly, the background-size property is not compatible with IE8. While there is a workaround mentioned here, in my opinion it causes more hassle than it's worth, as evident from the confusion in the comments on that solution.

Your best alternative might be to abandon the use of background-size altogether and instead replace it with a simple <img>.

The code snippet below demonstrates the issue. There is no bootstrap included, and you can observe that the desired outcome is achieved in every browser except for IE8, which presents something different compared to your intended design.

Note - stack overflow snippets are not functional in IE8. You will need to manually copy the code and create your own test .html files.

<style>
    #div1{
      width: 175px;
      height: 75px;
      background-image: url('http://placehold.it/350x150');
      background-size:cover;
    }
</style>


<div id="div1">
</div>

The suggested workaround in the linked Stack Overflow thread involves using the following approach:

<style>
    #div1{
        width: 175px;
        height: 75px;
        background-image: url('http://placehold.it/350x150');
        background-size:cover;

        filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
        src='http://placehold.it/350x150',
        sizingMethod='scale');
   }
</style>
<div id="div1">
</div>

In certain scenarios, this workaround does work! However, it should be noted that its effectiveness varies depending on individual cases.

Personally, I find it more effective to simply use an <img> tag and enclose it within a parent div to mimic a container.

<style>
    #div1{
        width: 175px;
        height: 75px;
    }

    img{
        width: 100%;
        height: auto;
    }
</style>
<div id="div1">
    <img src="http://placehold.it/350x150" />
</div>

If you decide to go with the first workaround provided, I strongly advise researching the drawbacks associated with such an implementation. AlphaImageLoader Filter.

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 technique for adding a stroke to an SVG border?

I am in the process of creating a gauge component using SVG. I'm using two strokes to show two states simultaneously. Currently, my output looks like this: enter image description here enter image description here However, I would like it to look li ...

What should I verify if the Grails application is not loading on IE9 exclusively?

In the process of developing a Grails project that incorporates some JS code, I encountered an issue where the project ran smoothly on Google Chrome (v34.0.1847.116 m) and Mozilla Firefox (v28.0), but failed to start on IE (v9.0.23), resulting in a blank s ...

Manipulate a JavaScript object with AngularJS - viewing and editing capabilities

I'm looking to create a dynamic list of objects where clicking on an entry displays the object details and an edit button. When clicking on the edit button, the details should disappear and a form for editing the object should appear on the right side ...

What are some ways to effectively incorporate the getRange() function within a forLoop while assembling data in Google Apps Script?

EDIT: To better illustrate my difficulty, I have included an example of my data that showcases the desired outcome: Example Data I hope this clarifies my request. I am seeking assistance with a complex issue: I am working on creating a summary sheet for ...

The jQuery show/hide functionality is malfunctioning

In my PHP code, I have the following loop: foreach ($sid as $key => $value) { $sql = " a sql query "; $vehicle->rowQuery($sql); $numRows = $vehicle->rows; while ( $data = $vehicle->result->fetch_assoc()) { $ ...

Encountering the value of 'undefined' when using jQuery

I need help with displaying values in my asp.net application using ajax. Here is the C# code snippet: [WebMethod] public static string fillvazh(int id) { List<object> Users = new List<object>(); DataTable dt = new DataTable(); ...

In vue.js, when utilizing the select all method for checkboxes, it is important to ensure that disabled checkboxes are not

I am working on a project where I have a table containing a list of checkboxes. When I click on the select all function, it selects all checkboxes including the disabled ones. However, I need to exclude the disabled checkboxes from being selected. ...

Designing personalized plugins with Typescript in Nuxt

In my Nuxt project, I have implemented a custom plugin file that contains an object with settings called /helpers/settings: export const settings = { baseURL: 'https://my-site.com', ... }; This file is then imported and registered in /plugi ...

Concealing the NavBar When Showing a Popup Using React

I am facing a challenge with hiding my bootstrap navbar that has a CSS property of position: sticky-top when I display a pop-up slideshow. I am working with React. I have attempted to target the navbar element in my click handler and adjust the display pro ...

jQuery modal popup failing to display the value of an element

When attempting to display content in a Bootstrap 4.0 modal on an ASP.NET Core 3.1 Razor page, the jQuery shown.bs.modal event seems to be failing to show the element value within the modal. Strangely, logging the assigned value to the console displays it ...

Saving integer data retrieved from DynamoDB in a React Native application

I need to store a user's progress by saving a value in a DynamoDB. While storing the value is not difficult, accessing this value for use in my application has proven to be quite challenging. When using dynamoDBWrapper.getItem(params), where the para ...

Troubleshooting data binding issues in Angular.js using Jade and Express

I've been diving into AngularJS using Dan Wahlin's tutorial (http://youtu.be/i9MHigUZKEM?t=13m35s). In my views/index.jade file, I've implemented the code below: !!! 5 html(data-ng-app='') head title Angular Tutorial body ...

What is the best way to export two functions from a server-side module in JavaScript?

Working with Node/Express. In my project, I have an index.js server file and a separate js module called validmoves.js. Usually, to export a single function from a module, I can simply use the following syntax: module.exports = shuffleFunction; Then, i ...

Unintended repetition with fetch() for loading a texture

I've been experimenting with using the fetch statement to fetch a local image and incorporate it into my (three.js) project. However, I seem to have created an infinite loop and I can't figure out why. Since the project is quite large, I've ...

AngularJS ng-repeat filter fails to update multiple columns at once

Here is the ng-repeat markup being used: <tbody> <tr ng-repeat= "(k, v) in loanapps | filter:SelectedStatus | filter:SelectedBorrower track by $index"> <td>{{v.Id}}</td> <td><a ui-sref="adminloandetails({loanid: ...

Guide on incorporating arrays into an array using JavaScript

Is there a way to achieve the specified outcome in JavaScript? I attempted to find a method for it on MDN but was unsuccessful. let a, b let allNumbers = [] for (a = 10; a < 60; a = a + 10) { for (b = 1; b <= 3; b++) { allNumbers.push(a ...

Transitions in Vue do not function properly when used in conjunction with a router-view containing a

Recently, I developed a component where I implemented router-view exclusively to facilitate route-based changes. It's worth mentioning that this is the second instance of router-view, with the first one residing in the App.vue component. Interestingly ...

File.type cannot be obtained in IE 11 and IE Edge due to compatibility issues

"change .btn-file :file" : "getfileinfo", getfileinfo: function(e){ var fileInput = document.getElementById('fileupload'); var file = fileInput.files[0]; if(!file || (file.type != 'text/plain' && file.type != ' ...

Preventing unauthorized access to PHP files by restricting calls to only those initiated by the website, and not through methods like Inspect Element

I have numerous php files responsible for updating my database, but I only want them to function when called in my code (typically through ajax). Currently, entering the URL of a php file directly causes the database to update. Additionally, if I insert a ...

Warning issued before exiting the page

I am working on a page where users can input data. Although it is not a typical form, they still need to save their information before leaving the page. I want to create a feature that alerts them if there are unsaved items when they try to navigate away b ...