Design comparison
Solution retrospective
I could not make it responsive. Can anyone help me with that?
Community feedback
- @elaineleungPosted about 2 years ago
Hi Osama, I'll try to offer some help here! π Here are some things you can try:
-
You'll first need to change your image from a
background-image
to animg
in the HTML. I suggest using a responsive image that hassrcset
, which allows you to store more than one image at a different size, and then the browser can choose which one to display at the breakpoint. Since you do not have a breakpoint yet, I will choose 550px for you. Also, I will change your.left
container to an.image-container
. Everything looks like this:// CSS // put this under the * rule at the top img { max-width:100%; display: block; } .image-container img { border-radius: 15px 0 0 15px; object-fit: cover; height: 100%; } // HTML <div class="image-container"> <img alt="Glass perfume bottle placed against a leafy background" srcset="images/image-product-desktop.jpg 600w, images/image-product-mobile.jpg 686w" sizes="(max-width: 550px) 686px, 600px" src="images/image-product-desktop.jpg"> </div>
-
For
.container
, change thewidth: 600px
tomax-width: 600px
. Next, addmargin: 1rem
to give it some spacing all around, and removeheight
here. -
Go to the bottom of the stylesheet and add a media query with a breakpoint of 650px:
@media (max-width: 550px) { .container { grid-template-columns: 1fr; } .image-container img { border-radius: 15px 15px 0 0; } }
That should make it responsive! To recap: (1) Use an image, not background image, and (2) add a media query to change the layout. For the next project, I suggest that you start building the mobile layout first and then the desktop. This is called the mobile-first approach, and it will make your code easier to write. Good luck!
Marked as helpful2@osamanazakatPosted about 2 years ago@elaineleung Thank You so much for the solution π
1 -
- @NaleekaPosted about 2 years ago
- favicon doesn't work because of spelling mistakes. It should belike this π
< link rel="icon" type="image/png" sizes="32x32" href="./images/favicon.png" />
- You could use media queries to make the website responsive.
Ex:-
@media screen and (min-width: 768px){ .selector{ width: 30vw; } }
hope this was helpful. Happy Codingπ¦ΈββοΈ
Marked as helpful1 - @raoufrofiPosted about 2 years ago
You can style your main for mobile
display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr 1fr;
and for tablet and desktop just change it from
grid-template-columns: 1fr 1fr; grid-template-rows: 1fr;
I hope it helps checkout My Solution that may be helpful
I hope it helps and best of luck
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