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

Single price Grid component

sass/scss
IO•710
@i000o
A solution to the Single price grid component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I'm proud of how quickly I completed this. My last project took too long so this was refreshing.

I also really enjoy using Grid, it makes things so easy.

I think I misused my classes in this one. I received some feedback to get into the habit of targeting classes, not elements, so that when I start working with more content, I'm not always making global changes all the time. I tried to implement this here, but in particular, I used a <section> element for the card, with no class, but when I went to apply a box shadow all the way around, it also included other <section> elements with classes. When I tried to replace the targeting with a class name instead, my design broke. I'd like to be able to use specificity to a better degree in future.

What challenges did you encounter, and how did you overcome them?

I had some challenges with sizing in the media queries. For instance, in the mobile design, I wanted the <li> in the <ul> to only take up one line, as visually, there is space. But <ul> has a margin-left that I was unable to remove, thereby making some <li> take up two lines.

That being said, I completed these media queries perhaps the fastest I ever have.

I had something happen that's occured for me before, where in Desktop, I make some corners have a border-radius, but in mobile, if the design becomes one column and I want to remove it, I'm unable. I haven't managed to figure this out.

What specific areas of your project would you like help with?

I'd like help with using classes for specificity. My HTML contains many <section> tags, which might not have been the best use. I also created <article> tags, but didn't call on them in the CSS. I'm not sure why my design breaks when I replace the card tag of <section> with a class target. I'd like to understand this as I didn't foresee it and attempting to do the box-shadow around the outside was one of the last things I tried to do.

How do I get rid of the <ul> margin? margin/padding: 0; has no impact.

Why am I unable to remove border-radius in the mobile design? I don't know why my declarations have no impact when I attempt it.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    markus•2,700
    @markuslewin
    Posted 4 months ago

    Hi!

    I think the core problem here is all of the nesting. It results in selectors with very high specificity scores, which makes them difficult to override.

    /* Specificity: (0,2,3) */
    body main section .bottom .left {
      border-bottom-left-radius: 12px;
    }
    
    /* Specificity: (0,1,3) */
    body main section .left {
      border-bottom-left-radius: 0px;
    }
    

    The border radius of .left will still be 12px, since the first rule has higher specificity. This is why you can't remove the margin of the list as well.


    Most layouts are simpler on mobile. It's therefore generally better to start with the styles for mobile, and then override those styles inside media queries targeting tablet and desktop:

    /* No nesting */
    /* Mobile-first */
    /* Simple class selector */
    .left {
      border-bottom-left-radius: 0px;
    }
    
    /* `min-width` targeting tablet+ */
    @media screen and (min-width: 720px) {
      /* Overrides mobile style */
      .left {
        border-bottom-left-radius: 12px;
      }
    }
    
    /* Desktop */
    @media screen and (min-width: 1015px) {
    }
    

    In summary, code mobile-first, target classes, and don't nest rules. This'll solve a lot of your problems! 🙂

    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