NFT Preview Card Component only using HTML and CSS
Design comparison
Solution retrospective
As easy it looks It was for me in the beginning, but after finishing all static part, I had to try little hard to make that image to hover with another small image as it was constantly going out of places. I had to do some search to make that possible. So I want to know easier way to make that hovering effect with another image using less code.
Community feedback
- @vanzasetiaPosted almost 2 years ago
Hello, Webdevsonu! 👋
To improve the overlay of the Equilibrium image, I recommend making the overlay with pure CSS.
But, you need to get the HTML right first.
- The image should be wrapped by an interactive element. I suggest using an anchor tag. Then, specify the
href="images/image-equilibrium.jpg"
. In this case, you can assume that the purpose of the link is to allow users to view the image. - The value for the
width
andhieght
attributes of theimg
element should be unitless. For your information, those values are used to specify the aspect ration of the image. The browsers use those values to know how much space the image requires before it can be fully loaded. As a result, it will optimize CLS (Cumulative Layout Shift). - The alternative text of the image is the label for the anchor tag. So, it can be "Preview Equilibrium".
- Then, remove the
div
for the overlay.
Use pseudo-element and background properties to create the overlay.
- First, create a pseudo-element from the anchor tag.
- Make the pseudo-element fill the entire image.
- Lastly, on hover (
a:hover::before
), add the cyan background color and the eye icon. - For the cyan background color, use
hsla
(orrgba
) color format.
One more suggestion is to make sure to fix all the issues that have been reported.
I hope this helps. Happy coding!
Marked as helpful0 - The image should be wrapped by an interactive element. I suggest using an anchor tag. Then, specify the
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord