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

Product page using flex in css

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

Solution retrospective


How do I get the main div in the middle of this whole page? It is located in the middle of the top line, but I want to locate it in the middle of the page. let me know how to do it

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Andreas Remdt•950
    @andreasremdt
    Posted over 2 years ago

    Hey @sujeong054,

    Nice job on finishing this challenge! It looks really good and you made good use of Flexbox. To answer your question:

    body {
      display: grid;
      place-items: center;
      min-height: 100vh;
    }
    

    With these three CSS properties, you can center everything within your body to the center. min-height: 100vh is important because it makes the body as big as your browser viewport. Without that line, the body always takes up only the space of its children, so you won't get the effect.

    With the above, you can reduce your CSS on the .main element:

    .main {
      display: flex;
      background-color: var(--White);
      border-radius: 15px;
      height: 650px;
    }
    

    Besides that, a couple of additional suggestions:

    • Try to use more semantic HTML elements. As the accessibility report already indicates, your page should have at least one main landmark, meaning that you should wrap your application in a main element. You can replace the div.main with a main.main to make that work.
    • The page is also missing a title. You've used a lot of div and span elements for the text content, which don't convey any semantic meaning. Screen readers and search engines will have trouble understanding what's the product title, its category, or description. I'd recommend the following HTML structure:
    <p>Perfume</p>
    <h1>Gabrielle Essence Eau De Parfum </h1>
    <p>A floral, solar and voluptuous interpretation composed by Olivier Polge, Perfumer-Creator for the House of CHANEL.</p>
    <div>
      <p><span class="sr-only">Current price:</span>$149.99</p>
      <p><span class="sr-only">Old price:</span>$169.99</p>
    </div>
    <button type="button">Add to Card</button>
    
    • With the above code, you get an h1 as the page title and a p for the description. From a perspective of accessibility, the pricing section a bit challenging - while we can visually indicate that the price is reduced, we have to explain it to those who can't see. I included span elements for that, made invisible via the .sr-only class. If you want to learn more about this technique, here's a great explanation.
    • All interactive elements like buttons or links should have some hover and focus styles. Your button lacks these, making it unclear whether it's clickable or not. You could change the background color on hover to be darker or brighter, just as an idea.

    Hope this answers your question and gives you some help. Let me know if you have any questions :-)

    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