Hi BDWNAV, good job putting this together! 😊 I got a few suggestions for you here:
- I would suggest wrapping the main-div inside the
<main>...</main
tag as this will semantically helps the code refer main content of the body. - Right now the component in the mobile have a stretched image with height that fills in the screen. This could restrict the flexibility of the component and one fix would be to wrap your card into a container class like as follow:
.container{
width: min(80%, 600px);
/*This will give the card a max width of 600px but will give the elements in it 80% maximum width of the screen (if its below 600px) */
margin-inline: auto; /*Centers the element */
}
.main-div{
min-height: 450px;
padding: 1rem;
/*Now you can remove the width constraint here and the 100% height & width property within the mobile view */
}
Then in html
<main class="container">
<div class="main-div">...</div>
</main>
- Instead of using the
<image/>
tag with CSS for handling the switching of the desktop and mobile images, try to use the picture element instead since this is a product image and is thus central to the card.
<picture>
<source media="(max-width: 375px)" srcset="images/image-product-desktop.jpg" />
<img src="images/image-product-mobile.jpg" alt="Glass perfume bottle placed against a leafy background" />
</picture>
Hope some of this can help you out, and really great work on the whole, so keep going!
@BDWNAV
Posted
@Douoo thanks for the help what do you mean by the image stretches out on mobile?
@BDWNAV Here is a screenshot: Screenshot You can see that the image is stretched (making a bit disoriented in its dimension). Perhaps you could use object-fit property to fix this with your current styling
.mobile-product-image{
...
object-fit:cover;
}
I prefer you use the <picture> tag though. More details here Picture tag
@BDWNAV
Posted
@Douoo oh I didn't even notice that it wasn't like that for me on mobile at all! Thanks for the help