Skip to content

Commit

Permalink
Save space for the image.
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp committed Dec 4, 2023
1 parent ec30578 commit cd773a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
26 changes: 19 additions & 7 deletions cigaradvisor/blocks/imagecta/imagecta.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
.home-tall-banner > a img{
.imagecta.block > a {
display: block;
margin: 0 auto;
}

.imagecta.block > a picture {
display: block;
position: relative;
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
border: 1px solid #000;
}
width: 100%;
height: 100%;
margin: 0 auto;
}

.imagecta.block > a picture > img {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
object-fit: cover;
object-position: center;
}
10 changes: 9 additions & 1 deletion cigaradvisor/blocks/imagecta/imagecta.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
export default async function decorate(block) {
const children = [];
const anchor = document.createElement('a');
anchor.append(block.querySelector('picture'));
const picture = block.querySelector('picture');
const img = picture.querySelector('img');
const ratio = (parseInt(img.height, 10) / parseInt(img.width, 10)) * 100;
picture.style.paddingBottom = `${ratio}%`;
anchor.style.maxWidth = `${img.width}px`;


Check failure on line 10 in cigaradvisor/blocks/imagecta/imagecta.js

View workflow job for this annotation

GitHub Actions / build

More than 1 blank line not allowed

anchor.append(picture);
anchor.setAttribute('href', block.querySelector('a').getAttribute('href'));
children.push(anchor);
block.replaceChildren(...children);
Expand Down

0 comments on commit cd773a0

Please sign in to comment.