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

Product Preview Card using HTML and CSS

@DivyanshiDetroja

Desktop design screenshot for the Product preview card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Need help centering div vertically

Community feedback

@orphandeity

Posted

flexbox is the easiest way to quickly center content. a quick google search will fill you in on the details, but what you want to do is put the following CSS rules on your parent container - probably the body element in this scenario, but whichever element is parent to the element you want centered.

.container {
  height:          100vh;    // this sets height to the screen height
  display:         flex;
  align-items:     center;   // center content vertically
  justify-content: center;   // center content horizontally
}

Marked as helpful

1

@DivyanshiDetroja

Posted

@orphandeity Thankyou so much, this fixed the responsiveness like butter

0
Hassia Issah 50,670

@Hassiai

Posted

Replace <center> with the main tag to fix the accessibility issues. click here for more on web-accessibility and semantic html

Add a tittle tag <tittle> in the head tag <head> to fix the error issue. Give the tittle tag a content, its content is the tittle of the page.

To center .container on the page using flexbox or grid instead of position: relative, add min-height:100vh; display: flex; align-items: center: justify-content: center; or min-height:100vh; display: grid place-items: center to the body.

To center .container on the page using flexbox:
body{
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
To center .container on the page using grid:
body{
min-height: 100vh;
display: grid;
place-items: center;
}

Use relative units like rem or em as unit for the padding, margin, width values and preferably rem for the font-size values, instead of using px which is an absolute unit. For more on CSS units Click here

Hope am helpful.

Well done for completing this challenge. HAPPY CODING

Marked as helpful

1

@DivyanshiDetroja

Posted

@Hassiai Thankyou so much for the help. Now my container doesn't jump slide and responsiveness is smooth. I'll definitely look into semantic html and be mindful incorporating it in

0

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