Skip to content

Commit

Permalink
Fix product detail image layout shift
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmastris committed Nov 21, 2023
1 parent d723c15 commit 3c47829
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions front-end/src/features/products/ProductDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ export function ProductDetail() {
return (
<div className={utilStyles.pagePadding}>
<section className={styles.summarySection}>
<div>
<img src={imagePath} alt={productData.name} className={styles.image}></img>
<div className={styles.imageContainer}>
<img
src={imagePath}
alt={productData.name}
height="500"
width="500"
className={styles.image}></img>
</div>
<div className={styles.summaryTextContent}>
<h1 className={styles.productName}>{productData.name}</h1>
Expand Down
15 changes: 14 additions & 1 deletion front-end/src/features/products/ProductDetail.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
align-items: flex-start;
}

.image {
.imageContainer {
width: 500px;
max-width: 100%;
}

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

Expand Down Expand Up @@ -53,6 +62,10 @@
align-items: center;
}

.imageContainer {
width: 450px;
}

.image {
max-height: 450px;
}
Expand Down

0 comments on commit 3c47829

Please sign in to comment.