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

html, css

brandie8•10
@brandie8
A solution to the Product preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Im just starting out. how can I do this better?

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • hitmorecode•7,540
    @hitmorecode
    Posted almost 2 years ago

    Good effort, as it is your page is not there yet. Here are a few things you can do to make it better.

    HTML

    • You can start with your html structure
    <body>
      <main>
        <div class="container">
          <div class="image">
            <picture>
    	  <source media="(min-width: ***px)" srcset="./images/image-product-desktop.jpg">
    	  <source media="(min-width: ***px)" srcset="./images/image-product-mobile.jpg">
    	  <img src="./images/image-product-desktop.jpg" alt="">
    	</picture>
          </div>
          <div class="text">
    				
          </div>
        </div>
      </main>
     </body>
    
    • Use the picture element to switch images from desktop to mobile, see above example
    • Switch h1 and h2. What you made h2 it's actually the main text on the page, so this should be h1.
    • You used <br> to separate the paragraphs, you don't need to do this. If you make the text container smaller, each text will jump to the next line.
    • For the price you created a div and placed two more divs inside. You can do this with just one div and place two <p> tags inside. After use flexbox to align them

    CSS

    • Make a habit of always add css reset to your css. Here is a simple css reset
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    • To be able to place the card in the middle of the page, you need to add this to your css
    body {
      min-height: 100vh; /* this makes the page responsive */
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    • In your css you have span {padding-left: 4px;}, but in your html there is no span to be found
    .price{
        display:flex;
        align-items: center; /* add this to align both prices horizontally */
    }
    
    • You can apply the same on the button.
    • The page is not responsive
    • You need to add the hover effect on the button.

    See if you can take it from here and if you need help let me know

    Marked as helpful
  • Caelus•520
    @Caelus111
    Posted almost 2 years ago

    You can start by centering everything using display:flex; and justify-content:center; and align-items:center; to the body element, then add background-color to it again, you got the layout right and you need to use multiple margins and padding to make it look like the original one. if this challenge is hard for you, you can always take it easy and start with the QR code component, and so on taking it step by step.

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

Oops! 😬

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

Log in with GitHub