@0xabdulkhaliq
Posted
Hello there 👋. Congratulations on successfully completing the challenge! 🎉
- I have a suggestion regarding your code that I believe will be of great interest to you.
PREVENT LAYOUT SHIFTS 📉:
- Your solution needs to be improved to prevent Cumulative Layout Shift (CLS) which results a visually unstable or janky website, particularly on mobile devices.
- This can happen because of leaving the Image and/or video elements without adding explicit
width
andheight
attributes.
- The multimedia elements like
img
which aren't explicitly declared with height and width attributes are usually re-sized using CSS (either on the image itself or the parent container). When this happens, the browser can only determine their dimensions and allocate space for them once it starts downloading the 'unsized images' and/or videos.
- You may notice that when the browser fetches these images, your page content is constantly being pushed down or moved around from its original position (i.e., layout shifts) as the browser resizes the images and positions them on your page.
- Currently the
img
element have no explicitwidth
andheight
to prevent CLS,
<img src="assets/assets/images/image-omelette.jpeg" alt="Omelette and salad" class="container__img">
- Here's an example which could help you to prevent CLS,
<img src="assets/assets/images/image-omelette.jpeg" width="1312" height="600" alt="Omelette and salad" class="container__img">
- The
height
andwidth
needs to have the actual measurements of that corresponding image. I shown mobile image as an example because Mobile devices can be easily affected by CLS than Desktop devices.
- I would like to recommend the article Use explicit width and height on image elements from GTMetrix to learn more about Layout Shifts and why's it needs to be prevented.
.
I hope you find this helpful 😄 Above all, the solution you submitted is great !
Happy coding!
Marked as helpful