![]() |
#1 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Aug 2020
Device: Kobo
|
Image resizing issues while using max-height/max-width
Hello,
First of all, sorry if I'm not using the correct terms or if my explanation is a little fuzzy, I'm very new to this and English isn't my first language. I'm working on a ePub containing a lot of images which is a first for me. Some images are extra wide, some are extra long. My goal is to use the same set of parameters on all images, no matter their dimensions or orientations, that would display each of them at the biggest possible scale without exceeding any ereader screen size and while keeping the correct aspect ratio. My current code is the following: Code:
<div style="width: 100%; max-height: 100%;"> <img style="max-height: 100%; max-width: 100%; display: block;" src="image.jpg" /> </div> 1. The container div would take 100% of the page width (that part seems to work); 2. The image, using "display: block" would try to take up 100% of its container width but would stop scaling it as soon as the height would reach 100% (that part doesn't seem to work). If I only have one image on the screen, it scales correctly but as soon as I have other elements displayed, it looks like they're squeezing the image and its container div. Example: in the following picture, I'd like for the images to be scaled according to the available width of the page/div and push the other elements (tables, texts) down instead of being squeezed by them (I put a 1px border on one of the image container div to confirm it was taking up 100% of the page width). https://i.stack.imgur.com/66cb6.jpg Does anyone know how this could be fixed? Thank you a lot for reading. Last edited by Detroa; 08-07-2020 at 11:35 AM. |
![]() |
![]() |
![]() |
#2 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 312
Karma: 3196258
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Someone more knowledgeable will likely reply, but I think your problem is twofold. First, each of those only take into account the height of the container, which for that parent div is (I assume) <body>; and second, AFAIK there is no reliable way to target the height of the viewport for ebook. I believe the only way to accomplish what you hope to do is via SVG wrapper, and even then I think you'd have to force page breaks around them.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Running with scissors
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,582
Karma: 14328510
Join Date: Nov 2019
Device: none
|
Also look at https://friendsofepub.github.io/eBookTricks/ where he recommends
Code:
img { object-fit: contain; } |
![]() |
![]() |
![]() |
#4 |
Running with scissors
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,582
Karma: 14328510
Join Date: Nov 2019
Device: none
|
For the sake of completeness I should say what I use, which is stuff I've gleaned from various sources:
Code:
img { max-width: 100%; object-fit: contain; width: auto; } Maybe also look in the ebook collection here at books uploaded by grannygrump; she focuses on illustrated books. |
![]() |
![]() |
![]() |
#5 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Aug 2020
Device: Kobo
|
Thank you so much to both of you for this explanation and that link.
Keeping in mind what phillipgessert said I fiddled with some of the code found in hobnail's link and the following paramaters seem to work! Code:
<div> <img src="image.jpg" /> </div> .div { width: 100%; max-height: 100%; page-break-inside: avoid; break-inside: avoid; } .img { max-width: 100%; max-height: 100%; } |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,064
Karma: 144284144
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#7 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,303
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
|
![]() |
![]() |
![]() |
#8 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,064
Karma: 144284144
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Most Readers that handle ePub use ADE. And ADE is on computers that use Overdrive or download DRMed ePub. ADE is the most used software for reading ePub. Sure that code may work on other programs, but when it fails on the largest market, it's a fail to use it.
|
![]() |
![]() |
![]() |
#9 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,064
Karma: 144284144
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Code:
div { height: 100%; max-width: 100%; max-height: 100%; } |
|
![]() |
![]() |
![]() |
#10 | ||
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,303
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Quote:
Quote:
Seems like if they want to sell on Kindle then they don't have to worry about if ADE works.... Correct me if I'm wrong, but there is a not-insignificant number of sales on the Kindle platform?? |
||
![]() |
![]() |
![]() |
#11 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,064
Karma: 144284144
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
![]() |
![]() |
![]() |
#12 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
|
Quote:
Dale |
|
![]() |
![]() |
![]() |
#13 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,303
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
OK....but does that mean that Kindle CARES about ADE in any way, shape, or form?
|
![]() |
![]() |
![]() |
#14 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
|
Quote:
Dale |
|
![]() |
![]() |
![]() |
#15 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,064
Karma: 144284144
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Resizing images, retaining width-height rato, and only if necessary. | Vanguard3000 | Sigil | 7 | 07-31-2015 10:43 AM |
Max Height in Calibre Viewer | XrXca | Calibre | 3 | 03-14-2014 10:46 PM |
KF8 max-width HTML CSS tag broken? | ekovv | Kindle Formats | 5 | 09-05-2012 04:57 AM |
Max-Height | theducks | Sigil | 6 | 09-02-2010 05:40 PM |
kindle 3 max. 3gb oder max. 3500 bücher | kakakanno | Amazon Kindle | 8 | 08-22-2010 03:27 AM |