Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
How to change the next/IMage SRC conditionally on various screensize in taiwind css?

I am using the next/Image component to set an image and add styling using tailwindcss, I got stuck at this point.

What I want?

I wanted to change the src of the image to be changed on the basics of screensize. Like if I am in sm screen size, then it should display IMG1 and after md screen size, it should display IMG2.

Also, I want to change the height and 'widthattributes of thenext/Image` component subjective to the different screensize.

How Can I do so?

Code

import React from "react";
import imgurl from "../public/dog.jpg";
import imgurl2 from "../public/Ash.jpg";
import Image from "next/image";

const Projects = () => {
  return (
    <>
      <div className="min-h-full container">
        
        
                    <Image
                      height={400}
                      width={800}
                      className="object-contain rounded-t-lg md:h-auto md:w-48 md:rounded-none md:rounded-l-lg "
                      src={imgurl2}
                      alt=""
                    />
           
      </div>
    </>
  );
};

export default Projects;

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I had solved the issue by this,

Putting the two images in a div wrapper and hiding them on the basis of screen size.

     <div className="block sm:hidden">
                    <Image
                      height={350}
                      width={700}
                      className="object-cover rounded-t-lg "
                      src={imgurl2}
                      alt=""
                    />
      </div>
      <div className="hidden sm:block">
                    <Image
                      width="500%"
                      height="1000%"
                      className="object-cover rounded-t-lg md:h-auto md:w-48 md:rounded-none md:rounded-l-lg"
                      src={imgurl3}
                      alt=""
                    />
      </div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!