4

Why isn't styling inside the Image component in NextJS not allowing me to manipulate my image. Am I missing something?

<Image className={styles.bg}
        style={{ transform: `translateY(${offset * 0.5}px)` }}
        src="/../public/bg.jpg"
        // width={2049}
        // height={2049}
        // objectFit="cover"
        layout="fill"
        quality={100}
      />
1
  • <Image className={styles.bg} style={{ transform: translateY(${offset * 0.5}px) }} src="/../public/bg.jpg" // width={2049} // height={2049} // objectFit="cover" layout="fill" quality={100} /> Commented Mar 2, 2021 at 4:52

4 Answers 4

1

If Next.js version is less than 12.1.1, this will not work. Onwards there is support for canonical style prop. With the style prop in support for props like layout, objectFit, and objectPosition is removed in Next.js 13.

Sign up to request clarification or add additional context in comments.

Comments

0

Other properties on the component will be passed to the underlying img element with the exception of the following:

style. Use className instead.

3 Comments

OP asked for styling, question is not about loading image, or how address it.
Can I see your the Image component?
0

NextJs v12.1.1 added the style prop to next/image.

1 Comment

Kinda late buddy 🙃
0

next 12 does not support styling the image tag directly, but the way to go about this is to put the image tag inside a div container, which we will apply the styling to, here is a sample

<div className={style.styling}>
   <Image src={image.url} width={100} height={100} />
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.