I have several images on a page utilizing basiclightbox. (which is truly fantastic)
The sizes of the images are set in the "basiclightbox.min.css" file.
Below is the content of the file with the specific line highlighted:
.basicLightbox{position:fixed;display:flex;justify-content:left;align-items:center;top:0;left:0;width:100%;height:100vh;background:#999999;opacity:.01;transition:opacity .4s ease;z-index:1000;will-change:opacity}.basicLightbox--visible{opacity:1}.basicLightbox__placeholder{max-width:100%;transform:scale(.9);transition:transform .4s ease;z-index:1;will-change:transform}.basicLightbox__placeholder>iframe:first-child:last-child,.basicLightbox__placeholder>img:first-child:last-child,.basicLightbox__placeholder>video:first-child:last-child
{display:block;position:absolute;top:0;right:0;bottom:0;left:0;
margin:auto;
max-width:75%;
max-height:50%}
.basicLightbox__placeholder>iframe:first-child:last-child,.basicLightbox__placeholder>video:first-child:last-child{pointer-events:auto}.basicLightbox__placeholder>img:first-child:last-child,.basicLightbox__placeholder>video:first-child:last-child{width:auto;height:auto}.basicLightbox--iframe .basicLightbox__placeholder,.basicLightbox--img .basicLightbox__placeholder,.basicLightbox--video .basicLightbox__placeholder{width:100%;height:100%;pointer-events:none}.basicLightbox--visible .basicLightbox__placeholder{transform:scale(1)}
By adjusting the "max-height:50%" value, you can change the size of the image up to the "max-width:75%". I want to modify the 50% to 75% for particular images that are too narrow and need to be taller.
To accomplish this, I created a second css file named "basiclightbox02.min.css"
This file contains only the relevant line:
{display:block;position:absolute;top:0;right:0;bottom:0;left:0;
margin:auto;
max-width:75%;
max-height:75%}
The page structure includes:
<button class="image1001">mom</button>
<button class="image1002">dad</button>
In the script section:
document.querySelector('button.image1001').onclick = () => {
basicLightbox.create(`
<img src="images/mom.jpg">
`).show()
}
document.querySelector('button.image1002').onclick = () => {
basicLightbox.create(`
<img src="images/dad.jpg">
`).show()
}
Also added basicLightbox.min.js.
For the full basiclightbox setup and demonstration, visit codepen:
https://codepen.io/electerious/pen/rLBvGz
There's usually advice against inline styling, but I struggled to make it work otherwise. Although if feasible, it could simplify the process.
Attempts to overwrite the original CSS values with height and width attributes were unsuccessful.
<img width="75%" height="75%" src="images/dad.jpg">
and
<img width="1400" height="900" src="images/dad.jpg">
Unfortunately, this did not reflect in the lightbox display.
I searched for ways to apply a different stylesheet to specific HTML elements but couldn't find a working solution.
Now I'm faced with the challenge of altering the size of "dad.jpg" and other images using a secondary CSS file only when necessary.
The original CSS would affect "mom.jpg", then the second CSS would target "dad.jpg", after which the first CSS would resume for subsequent images.
I believe creating a third CSS file with the initial line would help revert the precedence back.
{display:block;position:absolute;top:0;right:0;bottom:0;left:0;
margin:auto;
max-width:75%;
max-height:50%}
Though this approach seems viable, I am unsure how to write the original code that switches the line back and forth. While I excel at copying and pasting, coding from scratch in such scenarios still poses a challenge.
Here's a link to a codepen demonstrating the layout:
https://codepen.io/koretech/pen/jOpPVmg
You can also view the setup and demonstration on my test server:
Thank you all in advance, and have a wonderful year ahead!