Comments (6)
.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.
@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.
+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.
@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.
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.
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)
- CLI: initialise a new project with pages router without prompt HOT 3
- [15.0.0-canary.111+] Infinite loading page when fetch has "force-cache" in generateMetadata layout.tsx HOT 2
- [Bug?]: cssChunking / CSS Optimisations - Module CSS getting reset by tailwind's global styles HOT 5
- Cannot use local Next.js build as Next.js Dev Server (v14.2.6) HOT 1
- Docs: Playwright Component Testing
- Errors occurs when 'minimumCacheTTL' or 'icon.ico' are used with Turbopack HOT 3
- Location: iraq HOT 1
- > Location: iraq HOT 1
- Opening dev tools blocks app HOT 1
- Turbopack HMR does not work when using ternaries and JSX together. HOT 1
- Wrong segment rendered when quickly reload page and navigate browser history in Next.js 13+. HOT 1
- runtime env are not working on production build HOT 1
- Vercel Deployment Error: Module Not Found - Can't Resolve HOT 6
- Wrong segment rendered when quickly reload page and navigate through browser history in Next.js 13+.
- Middleware Unable to Access Updated Environment Variables Set Asynchronously in next.config.js
- Docs: Authentication page states encrypted sessions but the examples are signed instead, which is misleading
- next.config.cjs not detected HOT 1
- Memory issue with API routes and middleware
- Module not found: Fully Specified ESM Imports (with .js extension) in TypeScript with --turbo, related issue: #41961 HOT 1
- 404 Template Throws 500 Error when Using Middleware (v14.2.7) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.