Code Monkey home page Code Monkey logo

Comments (6)

tigerabrodi avatar tigerabrodi commented on September 23, 2024 1
.oil-analysis-span {
  padding-left: 2em;
  position: relative;
  height: 400px; /* Ensure the parent container has a defined height */
}

#oil-analysis2 {
  object-fit: contain;
  object-position: center;
  margin-right: 1em;
}

and then the updated JSX may look:

<div className="col-md-9">
  <div className="oil-analysis-span">
    <Image
      fill={true}
      id="oil-analysis2"
      src="/images/oil-analysis2.png"
      alt="oil-analysis"
      sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
    />
  </div>
</div>

from next.js.

tigerabrodi avatar tigerabrodi commented on September 23, 2024

@Elindo586 If you do fill I don't think you should specify the width and height since it'll fill?

Also, you may wanna specify width and height for the .oil-analysis-span element so the Image component knows how much to fill.

from next.js.

sagish avatar sagish commented on September 23, 2024

+1

When using layout="fill" with the next/legacy/image tag

<Image src="/images/birds.svg" alt="birds" layout="fill" />

the build fails on this error

ReferenceError: Cannot access 'd' before initialization

Next >=14.1.1
does not reproduce on 14.0.1

from next.js.

gustaveWPM avatar gustaveWPM commented on September 23, 2024

@Elindo586 If you do fill I don't think you should specify the width and height since it'll fill?

Also, you may wanna specify width and height for the .oil-analysis-span element so the Image component knows how much to fill.

Yes.
width and height properties are optional, depending on two scenarios:

  • fill property is true
  • the image is imported via a static import

from next.js.

Elindo586 avatar Elindo586 commented on September 23, 2024
height: 400px; /* Ensure the parent container has a defined height */

^^^ Well, that made the trick.

I previously gave the parent div height and width, and the image wouldn't shrink to be responsive, but giving the parent div just the value of height did the job.

I didn't see it in the literature, or missed it, and of course I just plain didn't know I must give it the parent div a size value.

Thank you much!

from next.js.

Elindo586 avatar Elindo586 commented on September 23, 2024

WAIT!!!

So, if you give the parent div a size for the height, it sure looks like the image is being responsive, but the div itself doesn't change height for smaller screens, so you end up with big spaces being used by the div even when the image gets smaller.

Usually, the the div and the image get smaller as you have smaller screens.

For this to work I have to do media queries to adjust the height of the parent div, which is not something I would have done before if I just specify the size of the image, but still better than providing a bunch of images to fix the wrong image size error from Google lighthouse.

Unfortunately, the technology to have a true responsive image doesn't seem to be there with the fill property..... and so far the fill property seems the only way to not get the image size error from the lighthouse.

from next.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.