Design comparison
Solution retrospective
What's an alternative way to set a card/container at the center of the page? I've use 'position: fixed' for these first two challenges and I feel using this property isn't going to work well on future challenges.
Community feedback
- @MelvinAguilarPosted about 2 years ago
Hi @funupulu ๐, good job for completing this challenge!
Here are some suggestions to improve your code:
- Centering the element with position would make your element behave strangely on some mobile devices. There are two modern CSS techniques to center elements instead of position:
Using flexbox layout:
body { margin: 0; width: 100%; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; }
Using grid layout:
body { margin: 0; width: 100%; min-height: 100vh; display: grid; place-content: center; }
More information:
- The Complete Guide to Centering in CSS
- A Complete Guide to Flexbox (CSS-Tricks)
- How TO - Center Elements Vertically (W3Schools) |
- CSS Layout - Horizontal & Vertical Align (W3Schools)
And remove all the position properties from the container:
.card { background-color: var(--card-color); border-radius: 15px; /* display: flex; */ /* flex-direction: column; */ /* height: 100%; */ min-height: 500px; /* width: 100%; */ max-width: 300px; /* margin: auto; */ /* position: fixed; */ /* top: 0; */ /* bottom: 0; */ /* left: 0; */ /* right: 0; */ padding: 15px; }
Tips:
- You could use position absolute in your "Go back" anchor tag
- Use
margin: 0.938rem
ormargin: 15px
in the.card
selector so that it has some space when viewed on mobile devices. - The
<div class="attribution">
needs to be wrapped in a<footer>
Element:
<footer class="attribution"> <p>Challenge by ... </p> </footer>
I hope those tips will help you.
Good Job and happy coding !
Marked as helpful1@funupuluPosted about 2 years ago@MelvinAguilar
Not trying to scare you away, but this is the most helpful feedback I've ever received since I started this journey. Thank you!!!!
1 - @correlucasPosted about 2 years ago
๐พHi , congratulations on your solution!๐ Welcome to the Frontend Mentor Coding Community!
Great solution and a great start! From what I saw youโre on the right track. Iโve few suggestions for you that you can consider adding to your code:
- Use
<main>
instead of a simple<div>
this way you improve the semantics and accessibility showing which is the main block of content on this page. Remember that every page should have a<main>
block and that<div>
doesn't have any semantic meaning. - Replace the
<strong>
containing the main title with<h1>
note that this title is the main heading for this page and every page needs one h1 to show which is the most important heading. Use the sequence h1 h2 h3 h4 h5 to show the hierarchy of your titles in the level of importance, never jump a level. - Add a margin of around
margin: 20px
to avoid the card touching the screen edges while it scales down. - Use relative units as
rem
orem
instead ofpx
to improve your performance by resizing fonts between different screens and devices. These units are better to make your website more accessible. REM does not just apply to font size, but to all sizes as well.
Here's my solution for this challenge if you wants to see how I build it: https://www.frontendmentor.io/solutions/qr-code-component-vanilla-cs-js-darklight-mode-nS2aOYYsJR
โ๏ธ I hope this helps you and happy coding!
0 - Use
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