Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 04-30-2025, 08:26 AM   #1
robertmchicago
Member
robertmchicago began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Apr 2025
Device: none
epub, images, and my codes

With my friend's help, I am making a reflowable epub in Sigil. One chapter has more than 350 definitions. Each definition has a heading and an explanation. More than 100 definitions also have an image. These definitions include a heading, an image, and an explanation. All images are full-width (width: 1200 pixels), and have a height between 300 and 900 pixels. No image has any caption.
Everything is working good. But we all know that images can create problems on different devices and apps, so I am trying to write the best code for images. Do I need to make any changes, adding or removing something, in these codes?
CSS:
img { display: block;
width: 100%;
height: auto;
object-fit: contain;
}
.image-setup {
text-indent: 0;
text-align: center;
margin: 0 auto;
width: 99%;
page-break-before: auto;
page-break-inside: avoid;
page-break-after: auto;
}

HTML:
<p>text text text</p>
<div class="image-setup">
<img src="image1.jpg" alt="beautiful image one">
</div>
<p>text text text</p>
Thanks for your time, your help and insights
robertmchicago is offline   Reply With Quote
Old 04-30-2025, 09:37 PM   #2
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,688
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Well, althought we don't know if you are working with epub2 or epub3, I would employ the following code:

Code:
img {
  display: inline-block;
  width: 99%; /* or whatever width you wish */
}

.image-setup {
  text-indent: 0;
  text-align: center;
  margin: 0;
}
RbnJrg is offline   Reply With Quote
Old 04-30-2025, 11:01 PM   #3
robertmchicago
Member
robertmchicago began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Apr 2025
Device: none
I don't know why you removed all those, e.g., "page-break-inside: avoid", it helps so the image will not be split across two pages.
Please I need help from someone who is professional or knows what is best.
robertmchicago is offline   Reply With Quote
Old 05-01-2025, 12:16 AM   #4
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 45,520
Karma: 168929301
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
If the image is too big to fit on a page, nothing will keep it from splitting. You might want to look at adding bits such as max-height and max-width. OTOH, since you appear to be using full page images with your splitting before and after, you may want to look at using an svg wrapper.

As for someone who is professional or knows editing epubs? I think you just insulted one of them.

BTW, page-break-before and page-break-after are replaced by break-before and break-after.

Last edited by DNSB; 05-01-2025 at 12:20 AM.
DNSB is online now   Reply With Quote
Old 05-01-2025, 04:30 AM   #5
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 13,837
Karma: 103895653
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Quote:
Originally Posted by robertmchicago View Post
I don't know why you removed all those, e.g., "page-break-inside: avoid", it helps so the image will not be split across two pages.
Please I need help from someone who is professional or knows what is best.
Because those don't do what you think they do.
Quote:
BTW, page-break-before and page-break-after are replaced by break-before and break-after.
And still don't do what you want if the image is too big. Using a % width with no margins and centred and height auto is mostly good, but fails if the aspect of the image is taller than the ereader screen at width: 100%. There are solutions to that.

I might not always agree with RbnJrg, but RbnJrg is very professional and expert.
Quoth is offline   Reply With Quote
Old 05-01-2025, 08:12 AM   #6
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,688
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by robertmchicago View Post
I don't know why you removed all those, e.g., "page-break-inside: avoid", it helps so the image will not be split across two pages.
Please I need help from someone who is professional or knows what is best.
I know what is best You don't need "page-break-inside: avoid" because in the img style I am employing "display: inline-block". That property avoids the split of the image. Try the code I posted and you will see it should work perfectly (with an image whose width is higher than his height; do the try with a with of 50% and you'll see how the image is centered without "margin: 0 auto"; that is also due to the property "display: inline-block" joined with the property "text-align: center" in the "image-setup" style). Of course, the img won't split but it can originate blank spaces; since we don't know if you are working under epub2 or epub3, I can't tell you how to avoid (if it were possible) those blank spaces. By the way, under epub3, "page-break-inside: avoid" is not honored by epub3 ereaders.

And thank you very much DNSB and Quoth for your words about me; many thanks.

Last edited by RbnJrg; 05-01-2025 at 08:38 AM.
RbnJrg is offline   Reply With Quote
Old 05-01-2025, 08:48 AM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,474
Karma: 145863170
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by RbnJrg View Post
I know what is best You don't need "page-break-inside: avoid" because in the img style I am employing "display: inline-block". That property avoids the split of the image.
Wouldn't the image have to split to the next screen it if did not fit on the space available on the screen?
JSWolf is offline   Reply With Quote
Old 05-01-2025, 09:21 AM   #8
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,335
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:
Originally Posted by JSWolf View Post
Wouldn't the image have to split to the next screen it if did not fit on the space available on the screen?
In case you missed his explanation (emphasis added)…

Quote:
Originally Posted by RbnJrg View Post
I know what is best You don't need "page-break-inside: avoid" because in the img style I am employing "display: inline-block". That property avoids the split of the image. Try the code I posted and you will see it should work perfectly (with an image whose width is higher than his height; do the try with a with of 50% and you'll see how the image is centered without "margin: 0 auto"; that is also due to the property "display: inline-block" joined with the property "text-align: center" in the "image-setup" style). Of course, the img won't split but it can originate blank spaces; since we don't know if you are working under epub2 or epub3, I can't tell you how to avoid (if it were possible) those blank spaces. By the way, under epub3, "page-break-inside: avoid" is not honored by epub3 ereaders.
Turtle91 is offline   Reply With Quote
Old 05-01-2025, 09:43 AM   #9
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,688
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by JSWolf View Post
Wouldn't the image have to split to the next screen it if did not fit on the space available on the screen?
If the width of the image is higher than its heigh, then the property "display: inline-block" will avoid splitting. It can generate a blank space but the image won't split.

The OP had employed in the "image-setup" style, the property "text-align: center" and in the img tag the property "display: block". But "text-align: center" is useless if an element is displayed as block. That one, only works for "inline" or "inline-block" elements. So to avoid properties "page-break-inside: avoid" and "margin: 0 auto", with "display: inline-block" the property "text-align: center" will work, the image always will be centered (no matter the width) and won't split. The code employed is minimun.

Last edited by RbnJrg; 05-01-2025 at 09:48 AM.
RbnJrg is offline   Reply With Quote
Old 05-01-2025, 11:14 AM   #10
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,474
Karma: 145863170
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by RbnJrg View Post
If the width of the image is higher than its heigh, then the property "display: inline-block" will avoid splitting. It can generate a blank space but the image won't split.

The OP had employed in the "image-setup" style, the property "text-align: center" and in the img tag the property "display: block". But "text-align: center" is useless if an element is displayed as block. That one, only works for "inline" or "inline-block" elements. So to avoid properties "page-break-inside: avoid" and "margin: 0 auto", with "display: inline-block" the property "text-align: center" will work, the image always will be centered (no matter the width) and won't split. The code employed is minimun.
Images don't split. They either go off the screen or drop to the next screen.
JSWolf is offline   Reply With Quote
Old 05-01-2025, 11:29 AM   #11
robertmchicago
Member
robertmchicago began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Apr 2025
Device: none
RbnJrg......First and foremost, please accept my sincere apologies if I hurt you in any way. We are working on epub3, but if a platform only supports epub2, we will need to work on that too. I will definitely try your codes. Thanks a lot. And Thank You for the explanations. I really like this forum!


Quoth......You talked about a problem and said there is a solution, but you didn’t tell us what the solution is. Could you please share it?
robertmchicago is offline   Reply With Quote
Old 05-01-2025, 11:31 AM   #12
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,688
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by JSWolf View Post
Images don't split. They either go off the screen or drop to the next screen.
Not always, depend on the ereader; with "display: inline-block" you'll be sure that images won't split.
RbnJrg is offline   Reply With Quote
Old 05-02-2025, 03:09 AM   #13
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Aren't you assuming a screen in portrait orientation? What if someone wants to read in landscape orientation (and I know someone who does)?
Jellby is offline   Reply With Quote
Old 05-02-2025, 05:27 AM   #14
robertmchicago
Member
robertmchicago began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Apr 2025
Device: none
Quote:
Originally Posted by Jellby View Post
Aren't you assuming a screen in portrait orientation? What if someone wants to read in landscape orientation (and I know someone who does)?
I already searched a lot about landscape mode and PC apps, but I couldn’t find any solution.
robertmchicago is offline   Reply With Quote
Old 05-02-2025, 06:30 AM   #15
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,335
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
Using ePub3 - if your targeted reader supports the css3 properties - you can use:
'object-fit: contain' as you mentioned, and maybe take a look at 'display: flex' .

You would need to provide fallback coding for devices that don't support them.

As DNSB mentioned, I use an svg wrapper that seems to be widely supported and works on ePub2/3 and doesn't care if the reading device is portrait or landscape, or if the image is wider than tall. But that really only works when you have an image taking up an entire page by itself. There are techniques to add text to the svg wrapper, but that is more in-depth. For your purposes I would stick with using the object-fit and display: flex for the ePub3 and fallback to the coding RbnJrg recommended.

Example SVG wrapper:
Code:
<html>
 <head>
    <title></title>     
    <style type="text/css">
        *   {margin:0; padding:0}
        div {width:100%; width:100vw; height:100%; height:100vh}
    </style>
</head>
<body>

<div>
  <svg 
    version="1.1"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    width="573px" height="800px" 
    viewBox="0 0 573 800" 
    preserveAspectRatio="xMidYMid meet">
     <image width="573" height="800" xlink:href="../Images/your_img.png" />
  </svg>
</div>

</body> 
</html>

Last edited by Turtle91; 05-02-2025 at 06:48 AM.
Turtle91 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word -> EPUB Chapter titles blank for Headings using Word's {TC...} codes GranitStateColin Conversion 2 12-21-2021 09:29 PM
images in epub alberto_savoini Tolino 1 01-10-2020 12:33 AM
Images exporting to epub carlsbad Workshop 5 09-13-2014 02:10 AM
Epub creation - pasting word and preserving codes Mr Pointy ePub 24 03-21-2014 02:55 PM
ePub with Images prdufresne Calibre 10 12-04-2010 01:55 AM


All times are GMT -4. The time now is 04:42 PM.


MobileRead.com is a privately owned, operated and funded community.