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

3 column card using Flexbox

Marina•70
@hellomarina
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


-I had trouble trying to align the buttons of the last box. The last box have an extra line of text and because of that the button of that card is more down. I couldn't figure it out how to fix that. I tried a few stuff but nothing worked so I will really appreciate some feedback about this issue!

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Parvathy Vazhoor•880
    @parvathyvd
    Posted almost 3 years ago

    Hi,

    Instead of giving height and width to the individual boxes give width to the parent.

    cards { display: flex; justify-content: center; align-items: center; max-width: 50rem; margin: 0 auto; /* min-height: 100vh; //remove this } also remove width and heights from the boxes .box-1 ,2, 3{ /* height: 450px; / / width: 250px; }

    That will fix your problem. Always try to use width instead of height. Let the padding, margins define their height. Hope this helps.

    Thanks

    Marked as helpful
  • Ahmed Bayoumi•6,700
    @Bayoumi-dev
    Posted almost 3 years ago

    Hey Marina,

    My suggestions:

    • To align the buttons of the last box, give all of the buttons margin-top: auto and give the parent of all buttons(box-1, box-2, box-3) display: flex:
    button{
        background-color: #f2f2f2;
        padding: 10px 25px;
        /* margin: 40px 0px;           /* <---- Remove */
        margin-top: auto;    /* <--- Add */
        border: solid #f2f2f2;
        border-radius: 18px;
        font-weight: 700;
        letter-spacing: 0.5px;
    }
    
    .box-1,
    .box-2,
    .box-3 {    /* <--- Add */
     display: flex;
     flex-direction: column;
    }
    img, button {    /* <--- Add */
     width: fit-content;
    }
    
    • Give the Cards Container width and height instead of giving it to each box...

    Also I suggest you instead of adding border-radius for each box, Add border-radius: 15px; and overflow:hidden; to Cards Container:

    #cards {
      display: flex;
      /* justify-content: center;      <--- Remove */
      /* align-items: center;      <--- Remove */
      /* min-height: 100vh;      <--- Remove */
      max-width: calc(300px * 3);    /* <--- Add */
      min-height: 500px;    /* <--- Add */
      border-radius: 10px;    /* <--- Add */
      overflow: hidden;    /* <--- Add */
    }
    
    .box-1 {
      background-color: #e38826;
      /* height: 500px;      <--- Remove */
      /* width: 300px;      <--- Remove */
      padding: 50px;
      /* border-top-left-radius: 10px;      <--- Remove */
      /* border-bottom-left-radius: 10px;      <--- Remove */
    }
    
    .box-2 {
      background-color: #006970;
      /* height: 500px;      <--- Remove */
      /* width: 300px;      <--- Remove */
      padding: 50px;
    }
    
    .box-3 {
      background-color: #004241;
      /* height: 500px;      <--- Remove */
      /* width: 300px;      <--- Remove */
      padding: 50px;
      /* border-top-right-radius: 10px;      <--- Remove */
      /* border-bottom-right-radius: 10px;      <--- Remove */
    }
    @media (max-width: 700px) {
      #cards {
        /* display: flex;      <--- Remove */
        /* flex-direction:column;      <--- Remove */
        /* flex-wrap: wrap;      <--- Remove */
        /* margin: 100px;      <--- Remove */
        max-width: 300px;    /* <--- Add */
        flex-direction: column;    /* <--- Add */
      }
    
      #cards > * {   /* <--- Add min-height for each box */
            min-height: 442px;
      }
    
      .box-1 {   /* <--- Remove all properties here and this class */
        /* height: 400px; */
        /* width: 300px; */
        /* border-top-left-radius: 10px; */
        /* border-top-right-radius: 10px; */
        /* border-bottom-left-radius: 0px; */
      }
    
      .box-2 {   /* <--- Remove all properties here and this class */
        /* height: 400px; */
        /* width: 300px; */
      }
    
      .box-3 {   /* <--- Remove all properties here and this class */
        /* height: 400px; */
        /* width: 300px; */
        /* border-bottom-left-radius: 10px; */
        /* border-bottom-right-radius: 10px; */
        /* border-top-right-radius: 0px; */
      }
    
      button {   /* <--- Remove all properties here and this class */
        /* margin: 0; */
      }
    }
    
    

    I think your code is now shorter...

    Don't repeat yourself (DRY)... This is a principle of software development.

    • After that, you need to center the component again by giving the parent element <main> containing the component(cards) the following properties:
    main {    /* <--- Add */
       display: flex;
       justify-content: center;
       align-items: center;
       min-height: 100vh;
     }  
    @media (max-width: 700px) {
        main { 
              padding: 24px;
        }
        //...
    }
    
    • When hovering over any button, its background should be transparent and the text color should be white as recommended in this challenge:
    button {
      //...
      border: 2px solid transparent;    /* <--- Add */
      cursor: pointer;    /* <--- Add */
      transition: background-color 0.3s, color 0.3s;    /* <--- Add */
      
    }
    button:hover {
      background-color: transparent;    /* <--- Add */
      color: white !important;    /* <--- Add */
      border-color: white;    /* <--- Add */
    }
    button:active {
    /* This effect works when you click the button  */
      transform: scale(1.05):     /* <--- Add */
    }
    

    Hope this help!... Keep 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

Oops! 😬

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

Log in with GitHub