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

Bryan Li 3,550

@Zy8712

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


I wasn't able to get the hover over the main image to work. Hope someone can teach me how I could integrate this feature into my code. Thanks.

Community feedback

@Klonnister

Posted

Hey there! And very well done, I like your solution aside from the hover over the image problem, it looks really cool.

I'll do my best to help you out with the hover effect on the image (this is what I did):

First I created a container for:

  1. The NFT image.
  2. The curtain (that's what I called the cyan hover effect).
  3. The curtain icon (the little eye icon which is shown as well).

We have three elements in total.

<div class="image-div">
<img src="./images/image-equilibrium.jpg">
<div class="curtain"></div>
<img src="./images/icon-view.svg" alt="" class="curtain-icon">
</div>
  1. These are the properties I settled for the container (this can apply to your .image-div class):
.image-div {
width: 100%;
border-radius: 0.60rem;
overflow: hidden; 
position: relative;
}

(Position relative is settled because we need to add position absolute to the curtain icon).

  1. I applied this css code to the NFT image:
.image-div img {
max-width: 100%;
height: auto;
display: block;
}
  1. Then, I added the cyan curtain as a div with background-color:
.curtain {
background-color: var(--Cyan);
width: 100%;
height: 100%;
position: absolute;
opacity: 0%;
transition: opacity 0.25s;
}

I added opacity: 0% so that when you hover over the image container (image-div), a transition will be done:

.img-div:hover .curtain {
opacity: 50%;
}

This will basically create the hover effect, the cyan div will be shown everytime you hover over the container. Read more about CSS Transitions

  1. Now we need to set the properties to the curtain icon which should also be shown on hover:
.curtain-icon {
position: absolute;
inset: 0;
margin: auto;
opacity: 0%;
transition: opacity 0.25s;
}

Just in case: inset: 0 is used to set the top, right, left and bottom properties to 0 (position: absolute), and margin: auto will automatically center the icon in the container.

Finally, we can set a transition for the curtain icon to show it everytime we hover:

.img-container:hover > a > .view-img {
opacity: 100%;
}

You can learn more about these efects here: W3S CSS Styling Images. Scroll down to the Image Hover Overlay section.

Hope I was helpful and happy coding!

Marked as helpful

2

@0xabdulkhaliq

Posted

Hello there 👋. Congratulations on successfully completing the challenge! 🎉

  • I have other recommendations regarding your code that I believe will be of great interest to you.

HEADINGS ⚠️:

  • This solution lacks usage of <h1> so it can cause severe accessibility errors due to lack of level-one headings <h1>
  • Every site must want only one h1 element identifying and describing the main content of the page.
  • An h1 heading provides an important navigation point for users of assistive technologies, allowing them to easily find the main content of the page.
  • So we want to add a level-one heading to improve accessibility by reading aloud the heading by screen readers, you can achieve this by adding a sr-only class to hide it from visual users (it will be useful for visually impaired users)
  • Example: <h1 class="sr-only">NFT preview card component</h1>
  • If you have any questions or need further clarification, you can always check out my submission for another challenge where i used this technique and feel free to reach out to me.

.

I hope you find this helpful 😄 Above all, the solution you submitted is great !

Happy coding!

0

@0marD

Posted

You can achieve this using CSS pseudo-elements, such as "after" or "before," which have a display property of "block" or "flex." When hovering over the image, the pseudo-element should be visible, and when not hovering, it should have a display property of "none." Alternatively, you can also use other elements like "img" or "div," and the steps would remain the same.

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