Design comparison
Solution retrospective
Hello everyone, here is my solution to the advice generator app challenge.
Built With
- JavaScript, Fetch API, HTML5, CSS3
I wanted to practice fetch api and mobile first so i choose this challenge. It was easy, simple and didn't take much time.
Question/Need Suggestions
- How do you guys normally center a div/container? Which method is easiest for you?
- How do you center it when the width/height is not fixed?
Looking forward to hearing your feedback! Thank you✨
Community feedback
- @somaye-beiranvandPosted about 2 years ago
Hi Rishma
As I had your problem before I Know what exactly you meen by asking the question.
In this project it's better to give this settings to body and just put your container inside it.
body{ width:100%; min-height:100vh; display:flex; align-items:center; justify-content:center; }
it't better to give body min-height not a fixed height, so if necessary it can stretch vertically.
great job on doing the project, happy coding😊
Marked as helpful0@rimshubPosted about 2 years ago@somaye-beiranvand Hello,
Yes that's what i usually go with when there's just one element to be centered and I also did the same in this challenge. You're right, thank you for mentioning it, min-height (also the max-width) would be the best choice here.
Thank youuu✨
1 - @DavidMorgadePosted about 2 years ago
Hello Rimsha, as always, great job getting the challenge done!
I will try answering your questions:
- The best way in my opinion is using flex in the parent element, this is by far in my opinion the easiest one, for example:
html
<div class='parentEl'> <div><p>I need to get centered!</p></div> </div>
css
.parentEl { display: flex; justify-content: center; align-items: center; }
Another way around could be using grid:
css
.parentEl { display: grid; align-content: center; justify-items: center; }
- The item will get centered anyway, if you setup a max-width it will center dinamically until it reach the
max-width
on resizing, same goes tomin-width
Hope my answers help you! if you have any questions, don't hesitate to ask, good solution!
Marked as helpful0@rimshubPosted about 2 years ago@DavidMorgade Yes i agree using flex is easiest one. Thank youuu for the feedback and answers!!
1
Please log in to post a comment
Log in with GitHubJoin 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