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

stats-preview-card-component-main

Kipo•80
@rezokip
A solution to the Stats preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Another Challenge nearly done..

Cannot find a way to fit the Image inside the parent on the desktop-version. Any help there?

And maybe any tipps on writing cleaner code? I think i make things more complicated then it needs to...

Appreciate any help.

Thanks.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Elaine•11,340
    @elaineleung
    Posted about 3 years ago

    Hi Kipo, what you need to do is: In img, add height:100% and change object-fit:contain to object-fit:cover so that the image won't be distorted when you add the 100% height. Contain means the container will contain the entire image even if there is white space showing, and cover means the image will cover the entire container even if parts of the image may be cropped.

    In terms of cleaner code, I think if your class names are clear and descriptive enough in terms of their function, half the work is done. The other half is just in how your structure your CSS and how you group containers using the appropriate elements, especially semantic HTML elements. I think it's not absolutely necessary to name every single element, but it's important to make sure you can easily find what you need just by looking at the selector. Sometimes I'd stop working midway just to rename half my classes because I find myself getting confused due to similar names.

    I might structure everything like this:

    <main class="container">
       <article class="card">
    
          <div class="image">
             <img>
          </div>
    
          <div class="content">
             <h1 class="title"></h1>
             <p class="body"></p>
             <ul class="stats">
                   // I wouldn't give individual class names to the items here
                   <li><span></span></li>
                   <li><span></span></li>
                   <li><span></span></li>
             </ul>
          </div>
    
       </article>
    </main>
    
    

    For the children in card I might even change them to BEM names, like card__image and card__content, as this would be helpful if I'm using Sass.

    Hope this helps!

    Marked as helpful
  • Joel•590
    @JoelLH
    Posted about 3 years ago

    Hey there, for the image, what you can do its remove object fit and use height 100% that will make the image strech to the size of the parent Also you are using the image for mobile version there's another image for the desktop version that will fit better. It has to change when you move from mobile to desktop.

    Good job, 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

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