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

- Semantic HTML5 markup - CSS custom properties - Flexbox

Desktop design screenshot for the Blog preview card coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


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

I would really like it if I could get some tips on how to center the card without having to change the height of the parent element

Community feedback

@TedJenkler

Posted

Hi @vic1500,

Great work on your project! Here are a couple of tips for centering elements on your site:

Flexbox Centering: One effective way to center your content is to set the body (or another container) to 100vh and 100vw, then use flexbox with align-items: center and justify-content: center. This will center your content both vertically and horizontally, and flexbox provides good responsiveness and customization options.

Absolute Positioning: Alternatively, you can center a card or any content using absolute positioning. Set the parent container (usually body or HTML if not manipulated) to position: relative, then set the content to position: absolute with top: 50%, left: 50%, and transform: translate(-50%, -50%). This method centers the content without needing to define explicit width or height, but flexbox is generally preferred for its responsiveness and flexibility.

Keep up the great work!

Best, Teodor

Marked as helpful

1

@wonddark

Posted

It is no possible to center an item without set the parent's height before, by default the parent will take the height of its children, you cannot center an item vertically if its height is the same as its parent's

Marked as helpful

1

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