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

Card component using HTML, CSS, and Flexbox

Tamera•110
@tlbodrick
A solution to the 3-column preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


For some reason, the cards resize randomly when changing the window size and I can't figure out why.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Alex Kim•1,325
    @alex-kim-dev
    Posted almost 4 years ago

    Hey Tamera, the cards resize vertically because the height of their content changes, as you resize the window. It's possible to make them of the same height if we apply align-items: stretch to their flex container, but then we should make some other changes:

    /* 750px+ */
    .main-component {
      margin: auto;
      display: flex;
      flex-direction: row; /* row is the default value, can remove this */
      justify-content: center; /* doesn't do anything in this case */
      align-items: stretch; /* change center to stretch, it's the default, so we can remove it too */
      max-width: 920px;
    }
    
    .main-component {
      margin: 0 1.563em;
      height: 100vh; /* to remove, we want the height of our cards to be auto */
    }
    

    The cards are ready, now we need to center the whole component on the screen

    body {
      height: 100vh; /* make body full screen */
      display: flex; /* now the .main-component auto centers, because it has margin: auto */
      margin: 0; /* remove the default margin so we don't get vertical scroll */
    }
    

    That's it, good luck & have fun on the next challenge!

    Marked as helpful
  • darryncodes•6,350
    @darryncodes
    Posted almost 4 years ago

    Hi Tamera,

    Good solution, nice and responsive - well done!

    • it might be nice to match the design and add in some button styling / hover affect
    • you might want to swap <div class="main-component"> with <main class="main-component">. This will help clear up one error on the accessibility report. Semantics is really important in your mark up

    All the best!

    Marked as helpful
  • P
    Patrick•14,265
    @palgramming
    Posted almost 4 years ago

    you need to put a controlled height on your card container you currently had 100vh but I put 60vh on it in web dev tools and then one each of your individual cards put a height of 100% on each of them

    thank should get you close

    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

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