The image is non-adjustable to different screen sizes

Currently, I am in the process of revamping a friend's website using Next.js and Tailwind. However, I've encountered a challenge with the background image specifically on iPhones. While it appears fine on browsers like Chrome and Safari as well as in full window and phone variants, it somehow compresses itself only on iPhones. Any thoughts on why this might be happening? Below are screenshots illustrating how it looks on the browser in phone mode versus how it actually appears on an iPhone. Additionally, I have included the code snippet for reference. It's possible that I may have overlooked something significant. Any assistance would be greatly appreciated. Feel free to inquire if you require more information.

.custom-img2 {
  background-image: url('https://images.squarespace-cdn.com/content/v1/57becd489de4bb4083a32846/1474057401289-YVPRNRZCTFWWCCZXT8DE/ccro-weee.png?format=2500w ') ;

}
<div>
      <div className='flex items-center justify-center h-screen mb-12 bg-fixed bg-center bg-cover custom-img2 sm:custom-img2 md:custom-img2 lg:custom-img2'>
       <div className=' top-0 left-0 right-0 bottom-0 bg-black/70 z-[2]' />
      <div className='p-5 text-white z-[2] mt-[-10rem] l '>
        <h2 className='text-5xl font-bold  '>About Us</h2>
        <p className='py-5 text-xl '></p>
      </div>
      </div>
      {/* Overlay */}
.............
..............
...............
.............
</div>

https://i.sstatic.net/ItQIj.png

https://i.sstatic.net/KN2Ch.png

I have experimented with Tailwind screens and next/image extensively for a whole day without success.

Answer №1

sm, md, lg are used to adjust styling for different screen sizes in Tailwind, although it is designed for mobile-first approach so they may not always be necessary.

If you're experiencing issues with your image display, consider using the bg property in Tailwind which worked well across various devices for me.

<div>
      <div className="flex items-center justify-center h-screen mb-12 bg-fixed bg-center bg-cover bg-[url('https://images.squarespace-cdn.com/content/v1/57becd489de4bb4083a32846/1474057401289-YVPRNRZCTFWWCCZXT8DE/ccro-weee.png?format=2500w')]">
        <div className=" top-0 left-0 right-0 bottom-0 bg-black/70 z-[2]" />
        <div className="p-5 text-white z-[2] mt-[-10rem] l ">
          <h2 className="text-5xl font-bold  ">About Us</h2>
          <p className="py-5 text-xl "></p>
        </div>
      </div>
    </div>

Answer №2

After countless months of struggling to find a solution on my website, I have finally cracked the code on this issue.

To ensure that your image is responsive on iPhones, you must include both of these classes:

class="bg-contain bg-cover"

If desired, you can also add bg-local and bg-center for further customization. Here's a snippet of my own code with a responsive image:

<div class="h-screen bg-cover bg-center bg-local md:bg-fixed bg-contain bg-no-repeat md:bg-cover md:bg-center md:mb-[-40px] max-w-screen-sm md:max-w-none bg-image-1" style="background-image: url('{% static 'about/image_1.JPG' %}'">

Although your code editor may flag it as redundant CSS, rest assured that after hours of trial and error, using both classes is the only reliable way to achieve responsiveness for large images on iPhones with Tailwind CSS.

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

The CSS styles do not seem to be taking effect on the Bootstrap

Here's a snippet of code extracted from my website's html and css files. My intention is to make the navbar slightly transparent with centered links, but for some reason, the css styles are not applying correctly to the navbar. HTML <body ...

Learn how to retrieve information from a component within tab panes once the user has entered data and clicked the "save" button on the react-bootstrap page

Currently, I am working on a project where I am utilizing react-bootstrap to create a user interface for entering customer information. The setup involves tabs structured as follows: <Tab.Container id="CustTabs" defaultActiveKey="Details"> ...... ...

Is it possible to override CSS classes in Ionic without using app.scss?

I'm currently working on designing a dark theme for my ionic application by watching this tutorial. It's been effective for most of the classes, however, I've encountered some CSS classes that only respond to overrides in app.scss. If I try ...

React Error: The module 'common' could not be located

I've been searching high and low on the web for a solution to this problem, but so far, nothing I've found has done the trick. I'm fairly new to React, but a friend of mine requested my assistance with some CSS work on his React project, so ...

Avoid reactivating focus when dismissing a pop-up menu triggered by hovering over it

I am currently utilizing @material-ui in conjunction with React. I have encountered the following issue: In my setup, there is an input component accompanied by a popup menu that triggers on mouseover. Whenever the menu pops up, the focus shifts away from ...

Assistance needed with CSS floating properties

Despite seeing many inquiries about float, I still can't pinpoint what's causing my issue. My objective is simple: GREETINGS FRIEND I aim for it to align just to the left of the unordered list. Referencing this solution, I attempted adding cl ...

What is causing the extra whitespace on the right side with container-fluid?

Could someone assist me with an issue I'm experiencing when using the container-fluid in Bootstrap? It seems to be leaving some space on the right side of my web page, and as a newcomer to Bootstrap, any help would be greatly appreciated. <link ...

Alert: Prop type validation failed - Prop `items[0]` must be an object, not a string, in order to be supplied to the `ImageGallery` component

As a newcomer, I feel like I might be overlooking something minor in this process. I am attempting to construct an array that resembles JSON objects for the purpose of passing it to react-image-gallery. You can refer to NPM react-image-gallery for more inf ...

You cannot change the value of constant 'setMessage'

Having a problem with the TextField component from Material UI. I am attempting to update the state in React using the onChange prop. However, I keep getting this error message saying "invalid assignment to const 'setMessage'". It' ...

What is the best way to utilize components depending on the screen size of the device?

Is there a way to show varying HTML elements or components depending on the device size? In React, you can utilize a package called react-responsive. However, in Next.js, when using this package in a component, server-side rendering does not occur on tha ...

Choosing different elements using identical classes in JQuery

Struggling with a coding problem that seems like it should be an easy fix, but can't quite figure it out. The HTML code I have is as follows: <section class="actualite"> <div class="actualite-text"> <h3 class="title"&g ...

Is it possible to change the CSS styling of a specific DIV class that contains nested anchor tags using jQuery?

The HTML: <div id="main_menu"> <a id="menu_item_articles" href="articles">articles</a> </div> The CSS: #main_menu { float: left; padding-top: 10px; vertical-align: middle; text-align: center; width: 500px; ...

Tensor data could not be located when attempting to utilize tf.browser.fromPixels() in Tensorflow.js

function processImage(base64Image) { let image = new Image(); image.src = base64Image; image.onload = () => { let tensorData = tf.browser.fromPixels(image, 3); Promise.resolve(tensorData).then(resu ...

Adding labels to a JavaScript chart can be done by using the appropriate methods

https://i.stack.imgur.com/uEgZg.png https://i.stack.imgur.com/y6Jg2.png Hey there! I recently created a chart using the Victory.js framework (check out image 1) and now I'm looking to incorporate labels similar to the ones shown in the second image ab ...

Intersection of content in panel-body using bootstrap tab pills

Can someone help me solve a major issue? I need the content of each tab to overlap as if they are unaware of each other. Currently, my code is saved in this fiddle: https://jsfiddle.net/axq882de/1/. When I click on different tabs, the contents should remai ...

Guide to center-aligning ElementUI transfer components

Has anyone successfully incorporated ElementUI's transfer feature inside a card element and centered it? https://jsfiddle.net/ca1wmjLx/ Any suggestions on how to achieve this? HTML <script src="//unpkg.com/vue/dist/vue.js"></ ...

How can a TypeScript Type be handed over as a prop to a React component?

Can you pass a TypeScript type as a property to a React Component? export type ActivitiesType = { RUN: "RUN"; WALK: "REST"; ROUNDS: "ROUNDS"; }; <MyComponent activity={ActivitiesType.RUN} /> Next, in MyComponent: const MyComponent = ({ act ...

While the Navbar component functions properly under regular circumstances, it experiences difficulties when used in conjunction with getStaticProps

https://i.stack.imgur.com/zmnYu.pngI have been facing an issue while trying to implement getstaticprops on my page. Whenever I try to include my navbar component, the console throws an error stating that the element type is invalid. Interestingly, I am abl ...

Adjust column content to fit width, instead of setting width to 100%

To create columns for the ul, I used flex-direction: column and flex-wrap: wrap. When the elements within the ul are split into multiple columns, each column takes on the width of the widest content in that column. However, if there is only one column, it ...

Is it possible to adjust responsiveness within the styled() function in Material-UI version 5 (MUI

Is it possible to utilize the responsiveness of MUI inside the styled() function? For instance: import { Button } from "@mui/material"; import { styled } from "@mui/system"; const MyButton = styled(Button)(({ theme }) => ({ wid ...