Inconsistent behavior with CSS Grid column widths in Firefox versus Chrome

As a beginner in CSS Grid, I recently encountered an issue where the layout differed between Firefox and Chrome. It seems like Firefox is adhering strictly to the grid width specifications set with "grid-template-columns", whereas Chrome is adjusting based on the content first before considering the grid width.

If you open the following pen link in both Firefox and Chrome, you'll notice the different results. How can this issue be resolved?

https://codepen.io/alosies/pen/OoXvre?editors=1100

.gridWrapper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  grid-template-areas: "palette questionDisplay questionDisplay questionDisplay ";
  grid-gap: 1rem;
}

.palette {
  grid-area: palette;
}

.questionDisplay {
  grid-area: questionDisplay;
}

.box{
  border: 1px solid grey;
}
<div class="gridWrapper">
  <div class="box palette">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci nobis aut labore repellendus exercitationem ab, illo sapiente fuga est provident, quam corrupti molestiae sint quibusdam aperiam. Deleniti ratione dolorum debitis.div
    </div>
  <div class="box questionDisplay">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nam exercitationem amet</div>
  
</div>

Answer №1

When setting your column order using grid-template-areas, there is no need to utilize repeat or auto-fit. These functions are specifically designed for managing a repeating pattern of tracks, which is not the case when you have created four columns with grid-template-areas.

The issue may be that conflicting instructions are being sent to different browsers, resulting in varied outcomes. Firefox and Edge might interpret it one way while Chrome handles it differently.

To resolve this, try the following code instead:

.gridWrapper {
  display: grid;
  /* grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); */
  grid-template-columns: minmax(150px, 1fr);  /* new */
  grid-template-areas: "palette questionDisplay questionDisplay questionDisplay ";
  grid-gap: 1rem;
}

.palette {
  grid-area: palette;
}

.questionDisplay {
  grid-area: questionDisplay;
}

.box {
  border: 1px solid grey;
}
<div class="gridWrapper">
  <div class="box palette">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci nobis aut labore repellendus exercitationem ab, illo sapiente fuga est provident, quam corrupti molestiae sint quibusdam aperiam. Deleniti ratione dolorum debitis.div
  </div>
  <div class="box questionDisplay">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nam exercitationem amet</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

HTML/CSS: Issue with image grid layout where images of different heights are not wrapping correctly

I have a Wordpress-based web project in progress at the following link: The current setup of the post thumbnails grid on the website was done with the assumption that all thumbnails will be the same height. However, I am looking to modify it so that the t ...

Is it possible to use jQuery to dynamically set the line-height of nested objects in CSS?

I am in the process of creating a horizontal family tree. Where I'm At - I am currently working on setting the CSS Line-Height to vertically center each item based on nested content. The Issue - The Line-Height value for nested items keeps growing e ...

Unable to reach the margin-left properties of the elements

I am facing an issue in accessing the current margin-left CSS property of the class .circle in the code snippet below. A demonstration of this problem can be found on a website called PLUNKr. The reason I need to access this property is because I have to ...

Guide on keeping a footer anchored at the bottom of a webpage

I have gone through numerous tutorials on how to position the footer at the bottom of my webpage, but I'm still struggling to accomplish it for my own site. Some of the resources I've consulted include: Understanding techniques to keep the fo ...

Styling the <div> element to create a unique rotation and tilt aesthetic

Would anyone be able to guide me on how to recreate the tilted style of the header section shown in the image using HTML and CSS? https://i.sstatic.net/mhJWA.png body { margin: 0px; background-color: #FFEF4C; } #header { background-color: #FF35 ...

Ant Design: Incorporating margin and padding causes slight rendering glitches in the markup

https://i.sstatic.net/BWmFU.gif https://i.sstatic.net/ZaLH8.gif When I apply margin and padding to this class, it starts twitching like in the first GIF. Removing the margin and padding fixes the issue, but I need them for styling. What is causing this ...

Ensure that the h2 text size is adaptable to mobile screens

Struggling to ensure my custom <h2> class remains responsive on mobile devices. My goal is to have this h2 class adjust to a text size of 49px when viewed on a mobile device. Here's what I have attempted so far: @media screen and (min-width: ...

Try rotating a triangle in 3D using either CSS or JavaScript

I want to create a right-angle triangle that looks like this . . . . . . . . . . . . . . . . . . but I also want to add a 3D animation that will transform it into a right angle like this . . . . . ...

Ensuring that the image perfectly fills the entire screen on an iPhone X using React Native

Looking for a solution to make my image fit the entire screen on the iPhone X simulator. I've tried adjusting the imageContainer width to "100%" and the container that encompasses everything, but haven't had any luck. Would appreciate any suggest ...

The alignment of inline divs is off and they are not forming a straight row

From my understanding, adding display:inline to divs with a relative position should align them (left to right) similar to float:left. I attempted both methods but with no success. Below is an example of my latest try with inline displaying. My goal is to ...

The Power of HTML Floating Elements

<nav> <div class="row"> <img src="resources/img/logo-white.png" alt="logo" class="logo"> <ul class="main-nav"> <li><a href="#">Food delivery</a></li> <li ...

Implement responsive data tables by setting a specific class for hiding columns

Having trouble assigning a specific class name to individual columns in datatables? It seems that when columns are hidden using the responsive extension, the desired class is not applied. Looking for a solution or workaround. Check out this example from D ...

Having trouble with Fancybox loading images from an external URL?

Here is an example of functioning HTML code: <a class="fancybox-gallery" href="http://sale.coupsoft.com/uploads/938218/logo.png"> <img class="animate scale animated" src="http://sale.coupsoft.com/uploads/938218/logo.png" alt="Image1"> ...

The overlay background on the image does not seem to be functioning correctly

I'm currently working on adding an overlay to my image in order to darken it and display text over the top. I've tried using absolute positioning for both the image and overlay, but the overlay ends up covering the entire window and sitting above ...

Bootstrap side navigation bars are an essential tool for creating

Is there a way to change the hamburger icon in Bootstrap's navbar-toggle to an X button? I want the side nav to slide to the left when clicked, and also collapse when clicking inside the red rectangle. Thank you. https://i.sstatic.net/nQMGs.png Code ...

What is the best way to update or include a new class in the jQuery mobile loader widget?

After reviewing the documentation at this link: I discovered a method to modify or add the default class of the loader widget, ui-loader. Despite my attempts, I have not been able to see any changes. You can view my demo here: https://jsfiddle.net/yusril ...

What is the best way to efficiently align items to the bottom of a sidebar in Bootstrap 5?

I am struggling to responsively align items at the bottom of a side nav bar created using Bootstrap 5. I have tried various approaches, including incorporating the .offcanvas class and tweaking the styling, but none of them have worked as expected. In the ...

Modifying CSS in JQuery does not seem to have a lasting effect

My webpage uses JQuery to dynamically hide and show different parts of the content when a button is clicked. However, I am facing an issue where the changes only last for a brief moment before reverting back to the default styling... Here is a snippet of ...

Can you explain the purpose of the text-align property set to justify-all?

Can you explain what the CSS property text-align: justify-all does? According to MDN, it should justify even the content of the last line. However, I am not seeing any changes in my Chrome browser: <p style="text-align: justify-all"> one two thre ...

Alter the row's color using the selection feature in the module

Is there a way to change the color of a row when a specific property has a certain value? I found a solution for this issue on Stack Overflow, which can be viewed here: How to color row on specific value in angular-ui-grid? Instead of changing the backgro ...