Last active
December 26, 2022 20:09
-
-
Save xxiz/a4d822c100481d02a6355d6c89b8fcbf to your computer and use it in GitHub Desktop.
background-image image optimization
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
// before | |
<div className="relative h-48 bg-center bg-cover rounded-xl" style={{ backgroundImage: `url(${cover_image})` }}></div> | |
// after (relative is added to classNames) | |
<div className="relative h-48 bg-center bg-cover rounded-xl"> | |
<Image | |
alt={title} | |
src={cover_image} | |
quality={100} | |
fill | |
sizes="100vw" | |
style={{ | |
objectFit: "cover", | |
}} | |
/> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment