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

Pricing Component with Toggle

John Q.•610
@romrauq
A solution to the Pricing component with toggle challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


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

Any help with using plain CSS to style the middle column's height to extend beyond that of both columns beside it will be much appreciated.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Aakash Verma•9,500
    @skyv26
    Posted 5 months ago

    Hi @romrauq,

    Great work so far! Your project looks promising, but I’d love to share a few suggestions that can help refine and enhance it further. 😊


    1️⃣ CSS Suggestion: Add Transform Scale Property

    • Feedback: The middle card already stands out visually with its unique style. However, using the transform: scale(1.1) property can make it pop even more by subtly emphasizing it. 🌟
    • Suggestion: Add the scale transformation specifically for larger screens and disable it on mobile screens. On smaller devices, the scaling might cause layout issues or make the card look squeezed.

    Why? Think of it as someone walking into a room and standing a bit closer than others—it naturally draws your attention without overwhelming the entire room!

    Here’s the updated CSS snippet:

    .pricing-column-middle {
        color: var(--Very-Light-Grayish-Blue);
        background: var(--Linear-Gradient);
        border-radius: 0;
        transform: scale(1.1);
    }
    
    @media (max-width: 768px) {
        .pricing-column-middle {
            transform: scale(1);
        }
    }
    

    2️⃣ JavaScript Suggestion: Simplify and DRY Your Code

    • Feedback: Your toggle logic is solid, but it can be made more compact and DRY (Don’t Repeat Yourself) to improve readability and maintainability.
    • Suggestion: By using a single loop and combining logic, you can make the code more concise without altering its functionality.

    Why? Imagine you're organizing two groups of items in a room (monthly and yearly prices). Instead of going through each group separately, you can organize both at the same time. This saves time and effort!

    Here’s the improved version:

    let toggleButton = document.getElementById("toggle-button");
    let isAnnually = false;
    let prices = document.querySelectorAll(".pricing-monthly, .pricing-yearly");
    
    toggleButton.addEventListener("click", () => {
        prices.forEach(price => {
            if (price.classList.contains("pricing-monthly")) {
                price.style.display = isAnnually ? "block" : "none";
            } else {
                price.style.display = isAnnually ? "none" : "block";
            }
        });
        toggleButton.style.justifyContent = isAnnually ? "flex-end" : "flex-start";
        isAnnually = !isAnnually;
    });
    

    Benefits:

    • Reduced repetitive code 🧹
    • Easier to understand and modify later

    3️⃣ Accessibility: Use Semantic Tags for Anchor Links or Buttons

    • Feedback: It’s crucial to use semantic HTML elements like <button> for actions or <a> for navigation. If the buttons or links in your project don’t use these appropriately, accessibility and SEO may suffer.
    • Suggestion: Update your code to reflect the intended purpose of each element. For instance:
      • Use <button> for actions like toggling plans.
      • Use <a href="#"> for links that navigate to other parts of the page.

    Why? Imagine a visually impaired user relying on a screen reader. A semantic <button> tells them, “This is a button; you can click it,” while an <a> suggests, “This is a link to another destination.” This clear distinction improves their experience.


    Let me know if you need further clarification or help implementing these suggestions! 🚀 Keep up the great work!

    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 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