002-blog-preview-card - HTML, CSS custom properties, CSS Flexbox

Solution retrospective
Some general remarks:
- CSS variables can be defined in a pseudo-element
:root
for global scope. - Variable font weights can be included from a file, instead of from Google's CDN.
- CSS resetting is important, e.g. for padding, margin and box-sizing.
I tried to keep in mind the principle of Cascaded Style Sheets, i.e. defining common properties as generally as possible. For instance, the font-family can be defined in the `` element, and can be tweaked further in the individual paragraphs if needed.
It is easy to center a block element both horizontally and vertically in a container using CSS Flexbox. Define the container as a flex container and set margin: auto
on the child block element.
However, there is no need to 'flexbox' everything. You can also use ad hoc margin-bottom
to space individual items.
I used media queries to define the layout for smaller screens:
@media all and (max-width: 500px) {
.card {
width: 327px;
}
}
I also needed to define a CSS width and height for an image, and the aspect ratio of this height and width did not correspond to the image's aspect ratio. Using object-fit: cover
scaled the image such that it covers the full area.
Note that the final result is not pixel-perfect with the frontendmentor.io solution. It is especially hard to get the vertical spacing between the elements right. We used the PixelParallel Chrome extension to do the comparison.
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on tomhaeck's solution.
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