What is the process for determining the width of a CSS Grid column in IE11 in order to implement animation?

The 'Slide' button allows for toggling a left-margin. I am currently seeking a solution to animate this left-margin using transitions, but it appears that applying a transition to any calc()ed element is causing a bug in IE11.

For a sample demonstration, please refer to the JS Bin link provided below: https://jsbin.com/qirozodete/1/edit?html,css,output or view the code snippet below.

This example represents a basic prototype of my current project. The goal is to create an element that smoothly slides and shrinks by one grid column at various screen resolutions. Currently, I am using a calc() function to determine the size of a grid column, which functions correctly on Firefox, Chrome, and Safari but not on Internet Explorer.

I have ruled out the option of using transform: translate as it prevents the element from shrinking properly, and the calculations required are more intricate than simply stacking translations.

Any suggestions or solutions would be greatly appreciated.

document.getElementById('slide-btn').addEventListener('click', function() { 
  document.getElementById('grid').classList.toggle('slide'); 
})
button {
  background: white;
  border: 1px solid black;
  padding: 5px 10px;
}

#grid {
  display: -ms-grid;
  -ms-grid-columns: 1fr 1fr 1fr 1fr;
}

#grid-item-1 {
  background: teal;
  -ms-grid-column: 1;
  -ms-grid-column-span: 2;
  height: 150px;
  transition: margin-left 500ms ease-in;
}

#grid.slide #grid-item-1 {
  margin-left: calc(100vw / 4);
}
<button id="slide-btn">Slide</button>
<div id="grid">
    <div id="grid-item-1"></div>
</div>

Answer №1

I ran a test on the provided code and successfully replicated the issue at hand. It seems like our best option is to utilize JavaScript to implement changes as a workaround for Internet Explorer. One approach could involve calculating the clientWidth value and toggling the marginLeft property accordingly.

Here's a snippet of sample code to demonstrate this:

document.getElementById('slide-btn').addEventListener('click', function() {
  var ml = document.getElementById("grid-item-1").style.marginLeft;
  var vw = (document.documentElement.clientWidth) / 4;
  if (ml == "") {
    document.getElementById("grid-item-1").style.marginLeft = vw + "px";
  } else {
    document.getElementById("grid-item-1").style.marginLeft = "";
  }
})
button {
  background: white;
  border: 1px solid black;
  padding: 5px 10px;
}

#grid {
  display: -ms-grid;
  -ms-grid-columns: 1fr 1fr 1fr 1fr;
  display: grid;
  grid-template-columns: repeat( 4, 1fr);
}

#grid-item-1 {
  background: teal;
  -ms-grid-column: 1;
  -ms-grid-column-span: 2;
  grid-column: span 2;
  height: 150px;
  transition: margin-left 500ms ease-in;
}
<button id="slide-btn">Slide</button>
<div id="grid">
  <div id="grid-item-1"></div>
</div>

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

Images in CSS not copied to the output directory when using Webpack

Using Webpack to bundle various javascript and css files on a website includes bundling bootstrap.css and chosen.css as part of the bundles. To achieve this, there is a main.js file serving as an entry point for importing all necessary files. The process i ...

Adjusting the page view when a collapse is opened

I am working on a website that features 3 images, each of which opens a collapse below with an embedded iframe website inside when clicked. I am trying to implement a function where the site automatically scrolls down to the opened iframe when an image is ...

Is it possible to export CSS stylesheets for shadow DOM using @vanilla-extract/css?

I have been exploring the use of @vanilla-extract/css for styling in my React app. The style method in this library exports a className from the *.css.ts file, but I need inline styling to achieve Shadow DOM encapsulation. During my research, I came acros ...

The sticky top feature of the Bootstrap 4 navbar does not function properly when it is nested inside a div

I am just getting started as a beginner working on a Web application and utilizing Bootstrap 4 for my web design. I have a quick question that needs some clarification. When the code is structured like this, the Navbar does not stay fixed at the top: < ...

How can I make HTML elements smaller to properly fit within a fixed-size div container?

Could anyone provide guidance on how to display HTML elements such as h1, h2, p, block quotes, and lists inside a fixed width and height <div id="preview"></div>? I want the content to be shrunk down so it fits perfectly scaled and proportion ...

Adjusting the height of each suggested item in Jquery autocomplete

I am currently facing an issue with the autocomplete input on my web app. The suggested list items have a height that is too small, making it difficult to select one item on a tablet using fingers. .ui-autocomplete.ui-widget { font-family: Verdana, Arial, ...

Navigate through an overflowing element in react/next

I have a component with a fixed width and overflow-x-auto. I want to hide the scroll bar and replace it with arrow buttons for scrolling left and right. How can I add this functionality to my component? Here is the code for my component: <div className ...

Creating a responsive layout for displaying products using CSS and HTML

I have a project that requires me to showcase products in a specific manner while being responsive. Here's what I want to accomplish: Based on your opinion and experience, what method do you recommend using to achieve this? Should I use divs, tables, ...

Using JQuery datepicker() with CSS class in ASP.net for dynamically generated TemplateFields

I have implemented TemplateFields in a Gridview to dynamically create textboxes as records are added. However, due to the limitation of not being able to have ASP controls with the same ID's, using ClientIDMode=Static is not an option for these contro ...

Curved edges, Layering, Content overflow restriction

My design consists of two circular divs with the border-radius property set to its max value. The first circle contains a header div with a unique background-color and overflow:hidden to create the illusion that the top portion of the circle has a differen ...

The <div> element is not compatible with the <canvas> element for use

I'm having trouble inserting a <canvas> animation within a <div> element. The current code displays the animation across the entire page, but I would like to contain it within a single section, like this: <div><canvas> </can ...

Placing pictures one on top of the other as shown in the illustrations

Just joined this community and hoping for some guidance. I'm working on arranging separate images in a specific layout like this. Here's my code on jsfiddle. This is the HTML I'm using: <body> <div class="grid-container" ...

Is the CSS3 bar chart flipped?

I'm currently developing a responsive bar chart, and everything seems to be going smoothly except for one issue - when viewing it in full screen, the bars appear to be flipped upside down. It's quite puzzling as all other elements such as text an ...

css position:absolute stacked

Looking for a solution, I'm trying to include a side menu (navbar) on my page by using position: fixed. However, I am facing an issue where all the HTML elements I attempt to add are ignoring it. Check out the positioning problem here. ...

Spacing between Div tags

Struggling with a tricky HTML cross-browser problem. The site was built by multiple people, making it quite messy, but needs to go live as soon as possible! Each of the 4 page layouts on the site are different and handled by separate classes. However, whe ...

Ways to showcase your style using Bootstrap

Can you help me figure out how to align this sidebar properly? I tried using the d-flex property but it doesn't seem to be working for me. The sidebar should be on the left side and the two containers should be centered. For a clearer explanation, pl ...

A guide on navigating full images using CSS

I am searching for a code that will enable scrolling through entire images on my landing page. It is a bit challenging to explain, but it is similar to the style of scrolling on tesla.com. Each scroll of the mouse wheel moves down one complete image. Can ...

Overflowing issue with jQuery Show DIV disrupting footer of other DIVs

I have utilized jQuery to create a simple show/hide functionality. Currently, I am facing two issues: 1) The hidden DIV is displaying over the footer instead of causing the footer to drop down automatically. How can I achieve this? 2) Is there a way to h ...

Columns in Bootstrap4 housing elements positioned absolutely

Recently, I've been developing a game that involves using absolute positioning for certain elements. This is necessary for creating moving animations where elements need to slide around and overlap to achieve a specific effect. As I focus on optimizi ...

Is there a way to adjust only the height of a responsive image?

Increasing the Height of an Image on a Mobile Device! I have an image that displays as the header of my website. When I resize the window to mobile format, the image resizes too. However, I want the height of the header image to be longer! Is this possibl ...