Responsive Product Preview Web Component Using HTML & CSS Flexbox
Design comparison
Solution retrospective
#what-i-found-difficult
- i found making the site fully responsive on all viewports and orientations a bit difficult to do.
- i found it hard to efficiently use css units and values
- i also found it hard to interchange the between desktop image and the mobile image properly.
#area-of-uncertainty
- the scalability of my code
- proper code formatting
#questions-on-best-practices
- how can i write better semantic Html?
- how can i utilize css properties properly especially in regards to the interchanging of the images?
- what are the best practices in case of accessibility here?
Community feedback
- @prantiknoorPosted over 2 years ago
I have another suggestion. Instead of adding
border-radius
on both elements, you can add it directly to.product-preview
. So then, you don't need to worry about it on mobile/desktop..product-preview { border-radius: 10px; overflow: hidden; } .product-image { /* border-radius: 10px 0 0 10px; */ } .product-main { /* border-radius: 0 10px 10px 0; */ }
Marked as helpful1@johnnysedh3llloPosted over 2 years ago@prantiknoor wow, that easy? i couldn't figure out. thank you I'll implement it. can you please explain a little bit what the
overflow: hidden;
decleration does to it?0@prantiknoorPosted over 2 years ago@johnnysedh3lllo It hides overflowing contents. As the image and content overflowing on the corners,
overflow: hidden
hides that.Marked as helpful1@johnnysedh3llloPosted over 2 years ago@prantiknoor thanks alot man. God bless you. just tried and it works like a charm.
0 - @cyberic67Posted over 2 years ago
Hello Johnny
For different imgage source based on screen size, you can use the "srcset" attribute in a picture element:
<picture> <source media="(min-width:660px)" srcset="images/image-product-desktop.jpg"> <img class="card__pic" src="images/image-product-mobile.jpg" alt="Product picture"> </picture>reference: https://www.w3schools.com/tags/att_source_srcset.asp
Marked as helpful1@johnnysedh3llloPosted over 2 years ago@cyberic67 thanks alot Eric, I'll try this new approach.
0 - @prantiknoorPosted over 2 years ago
Johnny, Congratulations!! 🎉 you have completed your first challenge.
Your style of asking questions is very well & appreciated.
I have some feedback.
.product-preview { /* You should give the card width. So you can get more control over your layout. */ max-width: 40rem; } .product-main { /* So you don't need to give width here. */ /* width: 40vh; */ /* This code will make the main content 50% of the card width. Now the image width will be 50% too. */ flex: 1 0 50%; } .product-image { /* You shouldn't hard code this. */ /* height: 57vh; */ object-fit: cover; height: 100%; }
1@johnnysedh3llloPosted over 2 years ago@prantiknoor thank you so much. i really appreciate you reviewing my code. I'll implement these new changes soon.
0
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