Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

gulp->CSS + JS

Vasily 250

@vasily-mishanin

Desktop design screenshot for the Pricing component with toggle coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Can anyone give me a hint on how to make this challenge without JS?

Community feedback

Mahesh Yadav 1,220

@Mahesh-yadav

Posted

You can use hidden checkbox to toggle prices. Follow following code:

<label class="switch" for="price-switch">          // add **for attribute** to link it with checkbox
   <input type="checkbox" id="price-switch">    // Remove this checkbox
   <span class="slider round"></span>
</label>

Place the checkbox as a sibling of <div class="cards-section">.

<input type="checkbox" id="price-switch">
<div class="cards-section">

Then add following styles:

<section class="card">
        <h3 class="card-title">Basic</h3>
        <div class="card-price"> <span class="price-monthly">19.99</span></div>
        <div class="card-price"> <span class="price-annually">199.99</span></div>
       
        // similarly for other cards
        <h3 class="card-title">Professional</h3>
        <div class="card-price"><span class="price-monthly">49.99</span></div>
        <div class="card-price"><span class="price-annually">49.99</span></div>

        // All monthly prices have same css class `price-monthly` and all annual plans have same css class

Hide one of the price category initially:

.price-monthly{
    display: none;
}

when checkbox is checked toggle display property:

#price-switch:checked ~ .cards-section .price-monthly{
    display: block;
}

#price-switch:checked ~ .cards-section .price-annually{
    display: none;
}
2

Please log in to post a comment

Log in with GitHub
Discord logo

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