Design comparison
Solution retrospective
Hello, I'm a newbie in Web Development world. Today, while doing this challenge project, I faced a problem with responsiveness.
Problem 1 ->
To match the given responsive design, I've to write two slightly different markup though I just only had to change the image source to another image for mobile preview.
Problem 2->
I used padding to have gap between the card-body elements and the whole card edge. But for mobile design, I can't use padding because if I used padding card-body elements was overflowing over the card component. That's why I had to use margin-left explicitly for each element within card-body.
Can any of you who is experienced, help to fix issue?
Community feedback
- @MelvinAguilarPosted almost 2 years ago
Hello there π. Good job on completing the challenge !
I have some suggestions about your code that might interest you.
Tips:
- Here is something strange, you shouldn't repeat all the HTML for the mobile view, because you are repeating a lot of code that can be avoided, to make a responsive website, the main protagonist are the CSS styles.
-
You can use the
<picture>
tag when you have different versions of the same image πΌ. Using the<picture>
tag will help you to load the correct image for the user's device saving bandwidth and improving performance. You can read more about this here π.Example:
<picture> <source media="(max-width: 460px)" srcset="./images/image-product-mobile.jpg"> <img src="./images/image-product-desktop.jpg" alt="{your alt text goes here}"> </picture>
HTML π:
- Use the
<main>
tag to wrap all the main content of the page instead of the<div>
tag. With this semantic element you can improve the accessibility of your page.
- Use the
<footer>
tag to wrap the footer of the page instead of the<div class="attribution">
. The<footer>
element contains information about the author of the page, the copyright, and other legal information.
- The
<h1>
is the most important heading on the page, In this challenge the perfumer's name can be considered like the title of the page, so it should be the<h1>
CSS π¨:
-
You should use the
box-sizing: border-box
property to make thewidth
andheight
properties include the padding and border of the element. This will make it easier to calculate the size of an element. You can read more about this here π.Most likely, if you don't use box-sizing, padding won't work on your component. Try to remove all margins, add the padding and use
* { box-sizing }
.
- Centering an element with
position: absolute
would make your element behave strangely on some screen sizes, "there's a chance the content will grow to overflow the parent". You can use Flexbox or Grid to center your element. You can read more about centering in CSS here π.
body { min-height: 100vh; display: flex; justify-content: center; flex-direction: column; align-items: center; } .card { /* position: absolute; */ /* top: 50%; */ /* left: 50%; */ /* transform: translate(-50%, -50%); */
I hope you find it useful! π
Happy coding!
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