Safari's compatibility issues with Next.js Images are preventing Flexbox from working properly

I'm trying to lay out Next.js Images using flex-wrap with a fixed height but variable width based on the image. I'm utilizing tailwind for this project.

Everything is working perfectly on Google Chrome as expected.

https://i.sstatic.net/KTTx9.jpg

However, when I view the layout on Safari, there seems to be extra space around the image. How can I resolve this Flex issue on Safari to make it display like it does on Google Chrome?

https://i.sstatic.net/eVg8E.jpg

Index.js

<div className="grid grid-cols-2 gap-8 md:flex md:flex-1 md:flex-wrap md:flex-row">
    <div className="relative h-96 bg-red-100">  
        <div className="h-full ck-product-image-container">
            <Image className="_image" src="" layout="fill" objectFit="contain"  />  
        </div>
    </div>
    <div className="relative h-96 bg-red-100">  
        <div className="h-full ck-product-image-container">
            <Image className="_image" src="" layout="fill" objectFit="contain"  />  
        </div>
    </div>
    <div className="relative h-96 bg-red-100">  
        <div className="h-full ck-product-image-container">
            <Image className="_image" src="" layout="fill" objectFit="contain"  />  
        </div>
    </div>
    <div className="relative h-96 bg-red-100">  
        <div className="h-full ck-product-image-container">
            <Image className="_image" src="" layout="fill" objectFit="contain"  />  
        </div>
    </div>
    <div className="relative h-96 bg-red-100">  
        <div className="h-full ck-product-image-container">
            <Image className="_image" src="" layout="fill" objectFit="contain"  />  
        </div>
    </div>
    <div className="relative h-96 bg-red-100">  
        <div className="h-full ck-product-image-container">
            <Image className="_image" src="" layout="fill" objectFit="contain"  />  
        </div>
    </div>
</div>

The majority of the CSS is handled in tailwind, but I did have to write some to target the Next.js Image property.

app.css

.ck-product-image-container > span {
  position: static !important;
  height: 100% !important;
  width: intrinsic;
}

Answer №1

First, ensure that the setup of postcss.config.js is done correctly:

module.exports = {
  plugins: [
    "tailwindcss",
    "postcss-nesting",
    "autoprefixer"
  ]
}

This information is sourced from the Tailwind CSS documentation.

As Tailwind CSS does not automatically add vendor prefixes to its generated CSS, it is recommended to install autoprefixer to manage this task, as illustrated in the code snippet above.

The issue may be related to the use of gap.

Notably, Safari has recently introduced support for this feature. If your browser is running an older version, it may not support this feature:

https://css-tricks.com/safari-14-1-adds-support-for-flexbox-gaps/

Answer №2

Flexbox may not be fully supported in all browsers. Check browser support here

To ensure compatibility, one approach is to use prefixes like -webkit-

    display: flex;
    flex-wrap: wrap;
    display: -webkit-flex;
    -webkit-flex-wrap: wrap;

/* For additional compatibility */
 display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;

If you're looking for a plugin that can help with this, check out this link:

Link to the plugin

Alternatively, there is another method which involves using:

display: -webkit-inline-box;

For more information on Flexbox compatibility across browsers, refer to:

https://github.com/philipwalton/flexbugs

If all else fails, consider using autoprefixer:

Info on autoprefixer and vendor prefixes

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

Varying heights based on the screen size

Currently, I am in the process of designing my website and incorporating some wave elements to enhance the background. However, I've encountered some issues when resizing the screen. Specifically, the waves seem to shift with a space between them as t ...

Add a class if the particular class is missing from the webpage

Seeking a solution in JS, I am facing a challenge in creating a series of elements with active states, each opening a caption below when clicked. Utilizing .addClass, .removeClass, and .toggleClass in combination, only one element can be active at a time. ...

What could be causing this Wordpress page to be unresponsive?

I am currently having trouble with the mobile display of a particular website. The site is not rendering correctly on mobile devices. Here is a snippet of the code from the issue: fiddle <div id="contactWrapper">. While the JSFiddle example shows a ...

Format six images in a horizontal row for desktop and ensure they resize appropriately for mobile viewing

I am looking to arrange images of different sizes in rows depending on the device orientation. For desktop, I want 6 images with proper margins, 2 images in a line for portrait, and 4 images for landscape orientation. Any extra images should be placed in a ...

The function getSelection().focusNode does not function properly within a specified ID

My current code allows for text to be bolded and unbolded using Window.getSelection(). I found the initial solution here: Bold/unbold selected text using Window.getSelection() It works perfectly without any issues. However, when I tried to modify the code ...

Tips for enabling auto-scroll feature in MuiList

Currently, I am working on a chat window component that utilizes Material UI for styling. I expected that setting a height or max-height on either the MuiList or MuiBox encapsulating the list would automatically scroll to the new message when it's sen ...

Connecting the same page to two different URLs in a NextJS app

Is it possible to display the city name in the URL before the page name when a user is searching for a specific city, and if not, show the normal URL? How can we make this work in Next Js? Example: http://localhost:3000/Delhi/furniture http://lo ...

Tips for enhancing webpage load times by optimizing CSS and jQuery file handling

As a beginner in HTML and CSS, I am facing slow loading times when testing my pages on a local server. This makes me concerned about the potential loading time on the internet. Currently, I have all the files included in the <head> tag at the top of ...

What are the steps to locally test my custom UI library package built with tsdx in a React.js project

I am currently utilizing tsdx to develop a React UI library, and I am looking to test it within my Next.js project before officially publishing it to the npm package. Initially, I attempted using npm link, which worked initially. However, when I made ch ...

Using Jquery variables for calculations and they do not work with numerical values

Hey there, I'm new to this so bear with me. I have a jQuery question that's puzzling me... I'm attempting to set the line height using the following method: var line_height = $('.container').css("height"); console.log(line_height ...

Retrieve and store session token using NextAuth authentication with Auth0

I am currently working on a Next.js application where I authenticate users using both nextauth and Auth0Provider. My main goal is to retrieve the token and include it in the headers of my API requests. Although I can see the token in the signIn callback, ...

The HTML/CSS authentication system is experiencing technical difficulties and is not functioning as intended

I came across this code on codepen.io and tried to implement it using the provided HTML and CSS. However, I encountered some errors during implementation. While the code works perfectly in the CodePen compiler, it doesn't seem to be error-free. One i ...

Next.js presents a challenge with micro frontend routing

In the process of developing a micro frontend framework, I have three Next.js projects - app1, app2, and base. The role of app1 and app2 is as remote applications while base serves as the host application. Configuration for app1 in next.config.js: const ...

Unable to get the DIV to float within its parent div

I'm having an issue with 2 DIV elements (the ones labeled "Module" below) not behaving as expected! When I try to float them so they appear side by side, they end up jumping outside of the parent container and falling below it. I've tried to trou ...

The span is unresponsive

When focusing on an input or checking its validity, the span should move up but it's not responding to any styles. <div class="login"> <span class="logtxt">Username or email</span> <input type=& ...

Issues with Monospace Google Fonts on JSFiddle are preventing them from displaying correctly

It's strange how monospace fonts from Google Fonts don't display properly on JSFiddle. Only sans-serif and serif fonts seem to be functioning correctly. ...

Ensuring only one group is open at a time in jQuery when a new group is opened

I need assistance in getting this functionality to work properly. My goal is to have only the clicked group open, while closing all others that are currently open. Here's a specific example of what I am trying to achieve: var accordionsMenu = $(&apo ...

Using CSS box-shadow to elevate an image

I am looking to create a background wrapper using CSS instead of an image. My goal is to add box shadow to achieve the same look as shown in the attached image. I understand that I will need to use the box-shadow property for this task. However, I am uns ...

Background image not displaying in new tab after Chrome extension installation

I have been developing a Chrome extension that alters the background image of a new tab. However, I have encountered an issue where the background image doesn't change the first time the extension is loaded. This problem has also occurred very occasi ...

Tips for efficiently exporting and handling data from a customizable table

I recently discovered an editable table feature on https://codepen.io/ashblue/pen/mCtuA While the editable table works perfectly for me, I have encountered a challenge when cloning the table and exporting its data. Below is the code snippet: // JavaScr ...