Skip to content

Commit

Permalink
Fix product feed image layout shift
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmastris committed Nov 21, 2023
1 parent 1822435 commit d723c15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 0 additions & 4 deletions front-end/src/App/utilStyles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@
margin-bottom: 0.8em;
}

.image {
max-width: 100%;
}


/* ===== Font Size & Weight ===== */

Expand Down
8 changes: 7 additions & 1 deletion front-end/src/features/products/ProductFeedItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export default function ProductFeedItem({ productData }) {
return (
<article className={styles.feedItem}>
<Link to={detailPath}>
<img src={imagePath} alt={productData.name} className={`${utilStyles.image} ${styles.image}`}></img>
<img
src={imagePath}
alt={productData.name}
height="500"
width="500"
className={styles.image}
></img>
</Link>
<div className={styles.textContainer}>
<div className={utilStyles.mb1rem}>
Expand Down
7 changes: 6 additions & 1 deletion front-end/src/features/products/ProductFeedItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
}

.image {
border-bottom: 1px solid rgb(240, 240, 240);
/* https://web.dev/articles/aspect-ratio#example_preventing_layout_shift */
width: 100%;
height: auto;
max-width: 550px;
aspect-ratio: 1 / 1;
}

.textContainer {
padding: 0.8em 6% 1.4em 6%;
border-top: 1px solid rgb(240, 240, 240);
color: rgb(15, 17, 17);
}

Expand Down

0 comments on commit d723c15

Please sign in to comment.