Design comparison
Solution retrospective
The challenge for this one was getting the buttons centered. I used position relative and moved them to the center that way.
What specific areas of your project would you like help with?Centering divs
Community feedback
- @Vyse1986Posted about 2 months ago
This is a really good start! You mentioned needing help centering divs, and IMO the easiest way to center divs is to use Flexbox. Using position works, but you'll need to use more code and it may take longer to troubleshoot. It would look like this
<div class="container"> <div class="container-content">Content 1</div> <div class="container-content">Content 2</div> </div>
.container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100dvh; gap: 1rem; }
All the flex items in the container would then be horizontally and vertically centered. The height will only be needed for vertical centering. 100dvh will use up the whole viewport height, so it can be less unless you want the container to be that large. The
gap
property lets you set a space between items and will be easier to maintain than using<br>
to create space.You'll be able to create responsive layouts more efficiently once you learn Flexbox!
Lastly, try importing the font that is specified in the style guide. Great job overall!
Marked as helpful0@gozicaPosted about 1 month ago@Vyse1986 Thanks for the input! The gap property is great—I had no idea about it before. I really appreciate it!
I tried the way you posted but it won't center the div in the middle of the page. It only centers it horizontally. I do it this way, but I feel like there is still an easier way.
.container{ padding: 10px ; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color:#1F1F1F; border-radius: 15px; width: 280px; height: 530px; }
0@Vyse1986Posted about 1 month ago@gozica You're welcome! Yes, that will center the container in the middle of the page. It may not work perfectly for your code because you have other things going on. Your method works perfectly fine! I recommend learning Flexbox because it will help you with layouts down the road. CSS Grid is another option that may be easier to understand than Flexbox.
Marked as helpful0
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