Styling Image Components for Mobile Devices on Next.js

Utilizing the Image Nextjs Component to center my image on the page has proven challenging. Despite aiming for the picture to maintain its true size, it appears pixelated. Additionally, when reducing the screen width, the image fails to display correctly for smaller screens, causing a portion of the picture to vanish.

<div
   style={{
     position: 'relative',
     width: '1000px',
     height: '500px',
     alignItems: 'center',
   }}
>         
 <Image src='/services.png' alt='' layout='fill' objectFitt='fill' />
</div>

The source of the issue seems to lie within the div's styling properties. I've attempted various adjustments to the width and height, yet the distorted image persists on the page. Even changing the objectFit attribute to 'cover' hasn't resolved the problem :( I welcome any guidance or insights on how to insert an image without sacrificing quality. Thank you immensely. The dimensions of the picture are: width=1454px and height=455px View the image here

Answer №1

To make the div responsive, change the width from 1000px to 100% and adjust the height based on different screen sizes. Follow this example:

                 <div
                    style={{
                        position: 'relative',
                        width: '100%',
                        height: '300px',
                        alignItems: 'center',
                    }}
                >
                    <Image src={main_image} alt='' layout='fill' objectFitt='fill' />
                </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

Guide on testing conditional rendering in components with Jest and Enzyme

Within my React component, I have a conditional rendering block that looks like this: {(props.email.primary.isPending) ? <PendingComponent emailAddress={props.email.primary.pendingEmail} /> : <SecondaryEmailContact ...

Customize your smartphone wallpaper with React Native

As a newcomer to React, I've successfully uploaded an image from my local phone gallery and stored its URI in a global variable. However, I'm struggling to figure out how to set this image as my phone's background image (not within React its ...

A guide on using Material UI - InputLabel in JavaScript

I'm currently integrating a form from this Codepen link into my project built with Codeigniter. However, I am encountering issues after incorporating material-ui into the CodeIgniter framework. The problems I am facing include an invalid token and an ...

Error: Unable to access the 'date' property of the 'Chat' type

chats object //I have an object containing chats retrieved from firebase date: nt nanoseconds: 269000000 seconds: 1684252737 lastMessage: {texts: 'So all the image disappears'} userInfo: {uid: '97iObwAHkQcnyq1CHgwnPg2f4Ga2', username: & ...

What is the reason for TypeScript not displaying a type mismatch error in this particular instance?

After starting to use React with TypeScript, I defined my types as follows: type CardInfo = { cardIndex: null | number; title: string; note: string; _id: string; from: string; cardId: string; }; type ContentType = { title: string; note: st ...

How can I create a single modal in Ionic 3 that occupies the full screen width and height?

Having trouble resizing my Ionic modal to full screen for just one modal, as Ionic's default settings are overriding any custom changes. I've attempted the following code snippet: @media only screen and (orientation: landscape) { ion-modal { ...

Conceal the block quotes while substituting with a newline

My HTML page contains numerous comments enclosed in blockquotes. I attempted to implement a feature that allows users to hide all the comments with just one click by using the following JavaScript code: const blockQuotes = document.getElementsByTagName(& ...

Having trouble loading CSS and JavaScript files in CodeIgniter version 3.0.4?

I am facing an issue with loading my CSS and JS files in the view file. I have already added them to the folder and set the base URL. These codes were working fine with a project I previously did on an older version of CodeIgniter. What could be causing ...

The issue of the fixed navbar overlapping the scrollbar of the page occurs when utilizing the overflow-y scroll feature

I am trying to create a web page with snap scroll and a fixed navbar that remains at the top. However, I'm facing an issue where the navbar is overlapping the right scroll bar, which should not be happening. If I remove the overflow-y property from th ...

What adjustments can be made to the Bootstrap code to prevent it from causing layout issues with the Signin Form and Footer?

Recently, I've encountered some challenges with the footer formatting on my website's home page and the sign-in form on a separate page. It appears that the Bootstrap framework at the top of the page is affecting these elements exclusively. How c ...

In what way does s% access the title attribute within the Helmet component?

I am seeking clarification on how the reference to %s is connected to the title attribute of the <SEO /> component within the <Helmet /> component in the gatsby starter theme. Can you explain this? Link to GitHub repo On Line 19 of the code: ...

Switching over to the latest version of Material-UI, v1.x.x

Currently, my app relies on Material-UI v0.17.0 which is not compatible with React v16.0.0. In order to make it work, I need to upgrade to Material-UI v1.0.0. I came across a migration tool here, but it only updates import statements. Many props have chan ...

Creating a nx workspace for vanilla JavaScript (Error: module 'typescript' not found) - Step-by-step guide

Looking to set up a new workspace for plain React applications. How can I do it? Create Workspace npx create-nx-workspace@latest # version 15.2.1 # style: package-based # distributed caching: NO Installing the react-package npm install -D @nrwl/react Cr ...

Entire body encompassing table

I am trying to create an HTML page with a table that spans the entire body and displays scrollbars when needed for both horizontal and vertical scrolling. Here is my current styling for the table: table { box-shadow: inset 0 0 10px #000; position: ...

What are some other options besides object-fit?

Currently seeking a replacement for the css object-fit property that functions properly in Firefox and IE. While it works well in Chrome and Opera, it is not compatible with Firefox and IE. Experimented with the imgLiquid Plugin, but encountered issues w ...

Can Google Charts columns be customized with different colors?

Is it possible to modify the colors of both columns in Google's material column chart? Here is the code I am using for options: var options = { chart: { title: 'Event Posting', subtitle: 'Kairos event p ...

Using CSS to remove the background of a dropdown button in a <select> element

I need to style a <select> element so that it appears like plain text until clicked, revealing the pulldown choices. Ideally, I would like to include small arrows to indicate multiple options, but I can add those as image overlays if necessary. My p ...

I am attempting to display the Δ symbol on my website, however, it is not appearing on the webpage

In my attempt to display my company logo on the website, I encountered an issue where the Δ symbol is not appearing correctly in the browser. strong class="footer-logo">KyΔnsys</strong To address this problem, I have implemented unicode charset=" ...

Limit the movement of objects in a canvas using React Three Fiber

Exploring the world of Threejs and react-three-fiber, I am wondering how to keep an object locked in place within the canvas. Even when the perspective camera rotates and moves, I want this object to remain stationary with fixed position and rotation. htt ...

Tips on dividing an Axios request into multiple files in ReactJS?

I've been working on a project that involves making Axios calls in multiple files, and I'm looking to modularize it by passing the call as a prop to other files that require it. Below is the componentDidMount() method containing the call: comp ...