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

Stats preview card component using HTML, CSS, Flexbox

accessibility
Alvin•140
@alvyynm
A solution to the Stats preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I used the background CSS property to add the images. Is this "best practice"? Is there any other better way to implement the same?

Looking forward to your responses 😄

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • David•7,960
    @DavidMorgade
    Posted almost 3 years ago

    Hello Alvin, great job with the solution it looks responsive and the layout is great, congratulations!

    If you don't mind, I would like to give you some suggestions.

    • I think that using an html is a better approach, for accesibility and for semantic purpouse, use background image when they really are background images. If you are struggling getting the effect with an html image, just think on wrapping it on a <div> and use that background color on the div to get the desired effect.

    • You should try getting your solution centered without using height: 120vh is moving your section to the bottom, instead of that, remove it and just use flexbox on the body to get everything center like this:

    {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
    }
    

    Setting the body to a min-height: 100vh is the best way to get the desired effect on this type of challenges!

    Hope my feedback helps you, if you have any questions don't hesitate to ask, great work!

    Marked as helpful
  • Lucas 👾•104,160
    @correlucas
    Posted almost 3 years ago

    👾Hello Alvin, congratulations for your new solution!

    Answering your question:Look that for SEO and search engine reasons isn’t a better practice import this product image with CSS (background-image) since this will make harder to the image be found. You can manage both images inside the <picture> tag and use the html to code to set when the images should change setting the device max-width depending of the device (phone / computer) Here’s a guide about how to use picture: https://www.w3schools.com/tags/tag_picture.asp

    To make the overlay effect exact as the challenge design you can take a shortcut and instead of using a long code you can do it by aplying mix-blend-mode and managing the opacity to blend the colors:

    .image-container {
        width: 100%;
        height: 200px;
        background: linear-gradient(rgba(99, 18, 150, 0.6), rgba(99, 18, 150, 0.6)), url(../images/image-header-mobile.jpg);
        background-repeat: no-repeat;
        background-size: cover;
        border-radius: 0.7rem 0.7rem 0 0;
        margin-bottom: 1.1rem;
    }
    

    Instead of this code just use (in this case you need the image inserted in the html as img or picture to make it work.

    img {
    mix-blend-mode: multiply;
    opacity: 75%;}
    

    ✌️ I hope this helps you and happy coding!

    Marked as helpful
  • Neil Kanakia•300
    @neilk17
    Posted almost 3 years ago

    Good work Alvin and nice display pic!

    One suggestion: On your parent-container, Instead of having height: 120vh; You could simply added a margin: 30vh auto; Since you have a height greater than 100% it isn't sized perfectly but the rest looks good!

    About the image background I was not sure what the best way to implement that was either but your solution is looking good!

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 all CSS, SCSS and Less files in your repository.

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.

How does the JavaScript validation report work?

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

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

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

Oops! 😬

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

Log in with GitHub