Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

NFT preview card component with HTML and CSS only

Mikhailβ€’ 440

@MikeBeloborodov

Desktop design screenshot for the NFT preview card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Had to use kind of a hacky method to make that hover effect on the picture. It works, but it will break on extra small screens. If you have any suggestions on how to improve it, please leave a comment, thanks!

Community feedback

Ferβ€’ 3,970

@fernandolapaz

Posted

Hi, regarding your question:

  • I leave you another way to do it in case you want to take a look (similar to what you did so you will understand it easily):

You can use the ::before pseudo-element to insert content (background and icon) to an element (the image).

Using position and width/height to cover the image and grid to center the icon. Then opacity to hide/show.

And we have a cleaner html with just the image.

.card__img {
position: relative;
}

.card__img::before {
position: absolute;    
content: url(images/icon-view.svg);    
display: grid;
place-content: center;
background-color: hsla(178, 100%, 50%, 0.5);
width: 100%;
height: 100%;
opacity: 0;
}

.card__img:hover::before {
opacity: 1;
}
  • And I take the opportunity for another comment if you don't mind:

When there is a hover state over an element it means that it is interactive, so there must be an interactive element around it (like a link or a button). So, we should use a <a> or <button> to wrap the image (depending on what happened when clicking on it).

I hope it’s useful πŸ™‚

Regards πŸ‘‹

Marked as helpful

1

Mikhailβ€’ 440

@MikeBeloborodov

Posted

@fernandolapaz thank you a lot, I will try it out!

0
Ferβ€’ 3,970

@fernandolapaz

Posted

@MikeBeloborodov

You are welcome. Any questions don't hesitate.

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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