Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

NFT preview card component

accessibility, styled-components
Sai•50
@A-C-Sai
A solution to the NFT preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hello Friends,

I got a few questions!! sorry for the long question :( ...

  1. To display the hover/focus styles when hovering over the cube image, I've initially added the hover styles using the ::before pseudo-element and set the opacity to 0. Then set the opacity to 1 when hovered. (Continuation of the question after code block).
<div class="avatar">
          <img
            class="cube-img"
            src="./images/image-equilibrium.jpg"
            alt="image of cube balanced on one of it's vertex and at equilibrium"
          />
</div>
.avatar::before {
  content: url("./images/icon-view.svg");
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 255, 247, 0.6);
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  opacity: 0;
  transition: opacity 0.1s ease-in;
}

.avatar:hover {
  cursor: pointer;
}

.avatar:hover::before {
  opacity: 1;
}

I initially did .avatar:hover .avatar::before { opacity: 1;} instead of .avatar:hover::before { opacity: 1;} as I thought .avatar:hover .avatar::before { opacity: 1;} meant when you hover over the .avatar div changes will be made .avatar::before, but nothing changed. Could someone explain why my initial code/ thinking was incorrect?

  1. In my HTML, I added the raw SVG code using <svg> to display the SVG image. Is there any other alternative?

  2. Any best coding practices I can improve on?

Please let me know anything else I haven't mentioned above and could improve.

THANKS IN ADVANCE (:

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Cosmo•590
    @cosmoart
    Posted almost 3 years ago

    Hi Sai!, Congratulations on completing this challenge, it looks great!, .avatar:hover .avatar::before { opacity: 1;} Translates to: When hovered in .avatar you will give an opacity of 1 to the ::before child from .avatar named .avatar.

    It would be something like this:

    	<div class="avatar">
    <div class="avatar"></div>
    </div>
    

    You can see it more clearly by hovering over the selector from a code editor like Visual Studio Code.

    Another way to display the SVG is using the <img> tag, something like this:

    <img src="image.svg" alt="...">
    

    If you want to know more about the differences is to use each one you can see this question on stackoverflow

    I hope you find it useful, Happy coding! 👋

    Marked as helpful

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub