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

Stats Preview card with full explanation using Flex-box and Mobile Fi

Hamzat Lawal•560
@EngineerHamziey
A solution to the Stats preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Thanks to my Mentors @vanzasetia and @grace-snow and other mentors for the review of my previous solutions, I can't wait to see your review on this one as well. I just think doing the correction and explaining it will help a lot of friends out there. Please feel free to point out my mistakes.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Grace•32,130
    @grace-snow
    Posted over 2 years ago

    Hi again

    This is using padding and margin in a strange way, making everything really complex in the text side of the card, and even the component itself (padding on the body and side margin on the card).

    Padding is for internal spacing. Think boxes. It's for creating space from the boundary. Padding will never collapse, so if two items have padding, double the space.

    Margin is for external spacing. This often only goes in one direction, or along one axis. Think block elements and creating space between them. Margin collapses, so if a heading has margin bottom and paragraph has margin top, the two margins will overlap and take up the same space on screen.

    On the text side of the card I would expect to see

    • padding on that half of the card
    • direct children of heading element, paragraph and list
    • margin top/bottom only on those three elements, no padding. They are all block level elements containing text content, so only need space between not inside.

    On the stats list, it is flex so again you don't need margin on elements inside or padding on that. Use the gap property and justify-content space-between

    All of this is really important to refactor and get comfortable with as it will become really difficult to manage larger projects later on if you use margin and padding so haphazardly. Have devtools open on the side of your browser, zoom in and out often and inspect a lot with devtools. Don't add extra divs unless you really need them and try to be really consistent in your use of margin/padding

    Marked as helpful
  • Raajzz•70
    @Raajzz
    Posted about 3 years ago

    Hello Hamzat, your solution was amazing, you especially nailed the responsiveness aspect of it, I do however wanted to share a cool property you can add for paragraphs, called line-height, this'll increase the space in between the lines of the paragraph.

    It is also recommended to use a minimum 1.5 or 1.6 as this will help people with cognitive concerns or other disabilities.

    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.

Frontend Mentor for Teams

Frontend Mentor for Teams helps companies and schools onboard and train developers through project-based learning. Our industry-standard projects give developers hands-on experience tackling real coding problems, helping them master their craft.

If you work in a company or are a student in a coding school, feel free to share Frontend Mentor for Teams with your manager or instructor, as they may use it to help with your coding education.

Learn more

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