Created
March 21, 2024 21:05
-
-
Save SevanBadal/006204c6010803a130af95e6c1d2abdd to your computer and use it in GitHub Desktop.
NextJs 14 Image component fills parent w/out overflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image from 'next/image' | |
import HeroImage from '/public/hero.jpg' | |
export default function Hero() { | |
return ( | |
<div style={{ position: 'relative', width: '100%', height: '100vh' }}> | |
<Image | |
src={HeroImage} | |
alt="Picture of the author" | |
fill | |
style={{ | |
objectFit: 'cover', | |
}} | |
/> | |
<div style={{ | |
position: "absolute", | |
top: 0, | |
left: 0, | |
right: 0, | |
background: "black", | |
zIndex: 10, | |
color: 'white', | |
width: '100%', | |
height: '100%', | |
opacity: '0.5' | |
}}> | |
<div style={{ | |
display: "flex", | |
justifyContent: "center", | |
alignItems: "center", | |
height: "100%" | |
}}>Hello World</div> | |
</div> | |
</div> | |
) | |
} |
Author
SevanBadal
commented
Mar 21, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment