I made the body a flex container so that I could center the design, but in order to make the justify-content property have any effect I had to add a height property and I'm not sure why. I presume it has something to do with how the body's height is defined, or maybe not defined. Any clarification would be appreciated. I'm pretty new to this.
Kegan
@KeganFAll comments
- @MooseCowBearSubmitted over 1 year ago@KeganFPosted over 1 year ago
Nice job completing the challenge! π
To (hopefully) answer your question: The body and the html elements have a default height of
auto
, meaning it will automatically adjust to fit its content. So as you create yourqr-container
, the body will change its size so that it is always the minimum height required to display its content. This is why you can't usejustify-content: center
without setting a height for the body; it is already vertically centered within the body (because there is no space above or below the container).When you set
height: 100vh
, you are overwriting the default ofauto
and telling the body to take up 100% of the viewport height. In some cases (especially with mobile devices) this can cause some issues with overflowing, so it is recommended to usemin-height: 100vh
instead, because if any content in the body is larger than the viewport itself, the body will still grow to fit its content properly.An extra piece of advice would be to check out some CSS resets. They help your webpage look the same across different browsers by resetting the default formatting of your webpage, and a lot of them will handle the
min-height: 100vh
for you. I like to use Andy Bell's CSS Reset, but there are many different ones you can try out.I hope this helped!
Cheers! π
Marked as helpful0 - @CaioSchwabSubmitted almost 2 years ago
This is my first solution, i hope you guys like it.
if you have any tip please share with me!
@KeganFPosted almost 2 years agoNice job completing your first challenge!
One thing I would suggest is to add some more semantic HTML by wrapping the contents of the card (
img
,h1
, andp
tags) in something like anarticle
tag.This reference talks about semantic HTML elements and says that an article "should make sense on its own, and it should be possible to distribute it independently from the rest of the web site."
Not only will an article element act as a container to group together all the elements of your card, it will also help make it reusable in other places!
Cheers! π
Marked as helpful1