Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aspect ratio in image container component on smaller screens #5179

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scss/_patterns_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
.p-image-container,
[class^='p-image-container--'] {
align-items: center;
display: grid;
display: flex;
justify-content: center;
text-align: center;
.p-image-container__image {
object-fit: contain;
}

&.is-highlighted {
background: $colors--theme--background-alt;
}

.p-image-container__image {
// max height prevents the image from stretching the container
// when the aspect ratio is set, and object-fit ensures the aspect ratio
// of the image content is maintained
max-height: 100%;
object-fit: contain;
}
}

.p-image-container--16-9 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<img class="p-image-container__image" src="https://assets.ubuntu.com/v1/9b4c074f-Kernelt%20industries-80-short.png" width="300" alt="">
</div>
</div>
<div>
<span>16:9 (with 16:9 image)</span>
<div class="p-image-container--16-9 is-highlighted">
<img class="p-image-container__image" src="https://assets.ubuntu.com/v1/7c9867c1-16x9.png" width="1200" alt="">
</div>
</div>
<div>
<span>3:2</span>
<div class="p-image-container--3-2 is-highlighted">
Expand All @@ -22,6 +28,12 @@
<img class="p-image-container__image" src="https://assets.ubuntu.com/v1/9b4c074f-Kernelt%20industries-80-short.png" width="300" alt="">
</div>
</div>
<div>
<span>2:3 (with 2:3 image)</span>
<div class="p-image-container--2-3 is-highlighted">
<img class="p-image-container__image" src="https://assets.ubuntu.com/v1/e97cdac9-2x3.png" width="1200" alt="">
</div>
</div>
<div>
<span>2.4:1 (Cinematic)</span>
<div class="p-image-container--cinematic is-highlighted">
Expand Down
Loading