Product preview card component using only CSS with Flexbox
Design comparison
Solution retrospective
Hey, it was my first more professional project ever. I used first time media queries, so i am unsure of that. Another problem was with centering all in flexbox. Should I start to use Bootstrap or stay in pure CSS for the time being? Feedback welcome. Thanks for your comments.
Community feedback
- @correlucasPosted about 2 years ago
👾Hello @CharlesSquirel, Congratulations on completing this challenge!
Your solution its almost done and I’ve some tips to help you to improve it:
1.Your component is perfect, but is not responsive yet, this is due the
fixed width
you've applied to the container.Look bothwidth
andmax-width
the main difference between these properties is that the first(width) is fixed and the second(max-width) isflexible
, for example, a component withwidth: 800px
will not grow or shrink because the size will be ever the same, but a container withmax-width: 800px
ormin-width: 800px
can grow or contract depending of the property you've set for the container. So if you want a responsive block element, never usewidth
choose ormin-width
ormax-width
.2.A better way to work this solution image, the product image is by using
<picture>
to wrap it on the html instead of using it as<img>
orbackground-image
(with the css). Using<picture>
you wrap both images (desktop and mobile) and have more control over it, since you can set in the html when the images changes setting the screen size for each image.ote that for SEO / search engine reasons isn’t a better practice import this product image with CSS since this will make it harder to the image.Here’s the documentation and the guide to use this tag:
https://www.w3schools.com/tags/tag_picture.asp
See the example below:
<picture> <source media="(max-width:650px)" srcset="./images/image-product-mobile.jpg"> <img src="./images/image-product-desktop.jpg" alt="Gabrielle Parfum" style="width:auto;"> </picture>
3.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.✌️ I hope this helps you and happy coding!
Marked as helpful0@CharlesSquirelPosted about 2 years ago@correlucas Thank you for your advices. They are very helpful :)
1 - @Deevyn9Posted about 2 years ago
Hi Karol, congrats on completing this project, seeing that is is you’re first solution here makes it even better, because everything turned out perfect. Congrats again.
Happy coding 🎈
1@NondabaPosted about 2 years ago@CharlesSquirel ,congrangrats on finishing the project. My question is how did you manage to change the layout of desktop to mobile as so in design images using media query?
0@CharlesSquirelPosted about 2 years ago@Nondaba I checked what's the different between desktop layout and mobile layout and put changes inside media query.
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