Design comparison
Solution retrospective
Would love to have some suggestions on how to have a more responsive component depending on the screen size.. And also on how to center everything in a cleaner way.
Community feedback
- @elaineleungPosted over 2 years ago
Hi Kenbak, congrats completing your first challenge, and welcome to Frontend Mentor!
It's good that you're asking about responsiveness for this challenge because this one doesn't particularly have a mobile view where the layout changes, but it's still good to think about what to do when the browser width changes. About your question, what I would do is to use responsive width properties such as
min-width
andmax-width
, and I would try not to use fixed widths/heights. You have awidth:300px
and also awidth:80%
for mobile view, and the300px
fixed width is what limits the responsiveness especially. You can try giving the component a max width and then see what happens in a smaller view. For this to work, I'd make these changes:-
On
container
, addmax-width: 300px
(or you can even try 350px) and delete thewidth
for both desktop and mobile views. Using a value like400px
or350px
could allow you to see the responsiveness in action, and then you can change it to 300px if you want. I would also remove the margins you have now and change that tomargin: 1rem
to make sure the sides don't touch the browser at smaller views when it's still responsive. -
For the
img
, I would change the width to 100% instead of the fixed width you have now. -
Lastly, I'd center the component using with these properties on the body selector:
body { min-height: 100vh; display: grid; place-content: center; }
Once again, great work on this first challenge, and do keep going! π
Marked as helpful1@KenbakPosted over 2 years ago@elaineleung Thank you very much for your quick feedback! I will try this asap and see how it goes!
0 -
- @correlucasPosted over 2 years ago
Hello Kenbak, congratulations for your first solution!
Answering your question:
There are 3 kind of width that you'll be working often,
width
,max-width
andmin-width
. Note that the difference between these three properties is thatwidth
is fixed, example,width: 320px
is an container that doesn't get bigger or smaller than320px
butmax-width: 320px
have the maximum of320px
and can contract when the screen scales down and adjust its size. Themin-width
is the opposite of max-width, so the container has a minimum size and can grow.In this challenge the container should have
max-width: 320px
to allow the card to grow 320px and scale down with the image when the window get smaller. This property will make the card both mobile and desktop screens. Remember to use min-width or max-width for responsive solutions and never with if you expect some change in its size.If youβre not familiar to
media queries
andresponsivity
, hereβs a good resource to learn it:https://www.w3schools.com/css/css_rwd_mediaqueries.aspHope this helps, happy coding π
Marked as helpful0@KenbakPosted over 2 years ago@correlucas Thank you very much. Responsivity is tough for me, but your answer helped me!
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