![]() |
#1 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 427
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Image styling css... what do all these properties do?
Judging from both MR searches and Google, this question is ripe for a flame war—this is NOT my intent.
I have not been able to discern what the various properties do in practice, both because they appear to behave differently in different apps and because they are described as doing different things by different users. For example, I've read that for a full-page, portrait mode image Code:
height: 100%; width: auto; In callibre, it seems to work until the reading screen is adjusted to 2-page mode, and then it gets horizontally smooshed. Alternately, I've seen the following recommendation... Code:
height: 100%; width: 100%; Another recommendation is... Code:
height: 100%; max-width: 100%; Code:
max-height: 100%; width: 100%; Also tried max-height/width variants to in include "auto", which again just blows up the image to full resolution in Sigil/PageEdit. Can someone please explain what I'm doing wrong? P.S. really unfamiliar with svg wrappers, so not sure I can use those effectively... but shouldn't this be doable with plain old css?? |
![]() |
![]() |
![]() |
#2 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,699
Karma: 168959600
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
For my purposes, I use an SVG wrapper for full page images which are mostly covers and some large images. For the cover and full page images, vh is set to 99 while the large images get a lower vh value. For small images, I just use a width: xx%; and height: auto;. On one occasion when working on a book which the author wanted to be read in portrait or landscape, I ended up with using media queries to set different values but that was a total PITA to set up. I attached a sample cover image style SVG wrapper. Normally, the styles are in the CSS stylesheet but I've embedded it here just to make it one block. The code is intended to look much the same on either ePub3 or ePub2 renderers.
Code:
<style type="text/css" title="override_css"> @page {padding: 0pt; margin:0pt} body {text-align: center; padding:0pt; margin: 0pt; } .cover {margin: 0; height: 99vh; max-width: 100%; overflow: hidden !important;} .picWrapper {margin: 0; padding: 0; height: 100%;} .pic {display: block; margin: auto; width: 100%; position: absolute; top: 0; bottom: 0; left: 0; right: 0;} </style> </head> <body class="cover"> <div class="picWrapper"> <svg class="pic" xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 1000 1500" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"><image height="1500" width="1000" xlink:href="../Images/cover.jpeg"/></svg> </div> |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 427
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
@DNSB, I'm sorry... all of that SVG styling is WAY over my head...
It looks like the height is set to 100% in the picWrapper and the svg... and the height/width dimensions are specified at 1000x1500... but what if the image isn't 1000x1500? Do you have an idea as to why the simple height/width properties are insufficient? |
![]() |
![]() |
![]() |
#4 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,556
Karma: 145863177
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
This is the code I use for a full screen image.
HTML: Code:
<div class="cover"> <img alt="" class="cover" src="../images/9781101543535_cover.jpg"/> </div> Code:
body { widows: 1; orphans: 1; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; text-align: justify; } img { max-height: 100%; max-width: 100%; } .cover { text-align: center; text-indent: 0; height: 100%; } |
![]() |
![]() |
![]() |
#5 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 427
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Thanks, JSWolf...
I gave this a shot, but it also smooshes the image horizontally in calibre, similar to the Code:
height: 100%; width: auto; Again, part of the issue here is that it seems that the simple Code:
height: 100%; width: auto; |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,683
Karma: 5703586
Join Date: Nov 2009
Device: many
|
As DNSB suggested use an svg wrapper. Sigil will even create an svg wrapper for your cover image when creating the cover.xhtml.
With it your image will scale more properly and you control if aspect ratio is kept or not. IMHO, svg is worh looking into. Last edited by KevinH; 06-09-2025 at 09:26 PM. |
![]() |
![]() |
![]() |
#7 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,711
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
If the e-reader is based on Webkit/Readium, "height: 100%" won't work. Or to make it work, more declarations than just "height: 100%" are needed. With this last property, we are telling the e-reader that the image will occupy 100% of the block that contains it. And here the problem arises, because if the containing block is a <div> and this block itself has a "height: 100%" value, for this height to be honored, we have to define that the <body> also has "height: 100%." And this causes more problems than it solves, unless the image has no text either before or after it; this is the typical case of a cover. If it's a cover image, for everything to work under Webkit/Readium you need the following code: Code:
html, body, div.picture { height: 100%; } img.cover { height: 100%; width: auto; } Code:
<div class="picture"> <img class="cover" alt="" src="../Images/your_image.jpg"/> </div> The code is greatly simplified if you're working in epub3 since instead of "%" you can use "vh" as the height unit and of that, is not needed to define a height for <html> and <body>. On the other hand, if the e-reader is based on RMSDK, the considerations are the same except that the <html> and <body> tags also don't need to have a height of 100%, but in this case, "vh" can't be used. There are many more considerations if the image you're working with is going to be included in the middle of a text. In that case, none of the above applies much. All that said, if what you need is code to handle a cover image, then use the following, which works everywhere (RMSDK, Webkit/Readium, epub2, epub3): Code:
<head> <title>Cover</title> <style type="text/css"> .cover { margin: 0; height: 99vh; max-width: 100%; overflow: hidden !important; } .picWrapper { margin: 0; padding: 0; height: 100%; /* this is for epub2 and ADE */ } @supports(display: flex) { /* but if the ereader supports epub3 */ .picWrapper { height: auto; /*then height is "auto" instead of "100%" } } .pic { /* this reserves an space for the svg wrapper equal to the full screen, where the image is going to be inserted */ display: block; margin: auto; position: absolute; top: 0; bottom: 0; left: 0; right: 0; } </style> </head> <body class="cover"> <h1 style="display:none" title="Cover" class="sigil_not_in_toc"></h1> <div class="picWrapper"> <svg class="pic" xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 10 600 900" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="900" width="600" xlink:href="../Images/cover.jpg"/> </svg> </div> </body> ![]() Last edited by RbnJrg; 06-09-2025 at 08:14 PM. |
|
![]() |
![]() |
![]() |
#8 | |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,699
Karma: 168959600
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
As you can see from @RbnJrg's post, the answer can get even more complex but then copy/paste becomes your friend. Copy the code and then modify as needed (for instance, my cover images are all 1000x1500 or 1125x1500 pixels so I have 2 clips to insert that code. Last edited by DNSB; 06-09-2025 at 08:05 PM. |
|
![]() |
![]() |
![]() |
#9 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 427
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Thank you all, especially RbnJrg.
I have some serious reading and re-reading to do. Learning is hard. Part of the issue here is that the images I'm dealing with are a) not covers, b) not of a consistent height/width, and c) many in number. So I'd hoped there was something that could be generically (and effectively) applied with a simple "class" modification... maybe a <div> if it was being especially intransigient... But no dice... |
![]() |
![]() |
![]() |
#10 | |||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,711
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Code:
img.all { display: inline-block; width: 99%; /* or whatever width you wish */ } .image-setup { text-indent: 0; text-align: center; margin: 0; } Code:
<p>text text text...</p> <div class="image-setup"> <img class="all" src="../Images/your_image.jpg" alt=""> </div> <p>text text text...</p> Quote:
Code:
div.wrapper { height: 60%; /* This is for ADE */ height: 60vh; /* This is for Webkit/Readium */ } Code:
<div class="wrapper"> <svg...><image.../></svg> </div> Quote:
Code:
img.all { display: inline-block; width: 99%; /* or whatever width you wish */ } Code:
.special_width { width: 50%; /* Or whatever you wish */ } Code:
<div class="image-setup"> <img class="all special_width" alt="" src="../Images/your_image.jpg" /> </div> |
|||
![]() |
![]() |
![]() |
#11 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,556
Karma: 145863177
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
This is as small as the viewer will go while showing the full image. Last edited by JSWolf; 06-10-2025 at 06:04 AM. |
|
![]() |
![]() |
![]() |
#12 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 427
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Thank you, RbnJrg.
FWIW, I suspect that the non-cover, full page images I'm dealing with may often behave somewhat similarly to cover images in that I tend to place them either at the end or beginning of a chapter as a separate html file to avoid sudden gaps in the text. Also, in your example Code:
<div class="wrapper"> <svg...><image.../></svg> </div> |
![]() |
![]() |
![]() |
#13 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,556
Karma: 145863177
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Last edited by JSWolf; 06-10-2025 at 06:05 AM. |
|
![]() |
![]() |
![]() |
#14 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 448
Karma: 3886916
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
|
One of the things I still use in the Calibre editor is the Insert Image tool. If you are inserting a full page image, it gives you this:
Code:
<div style="page-break-before:always; page-break-after:always; page-break-inside:avoid"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" height="100%" viewBox="0 0 1128 671" preserveAspectRatio="xMidYMid meet"><image width="1128" height="671" xlink:href="../birdsargue.jpg"/></svg></div> It reads the size numbers from the image and puts them in for you. I don't know how widely this works in terms of all the different readers, but it is fine for my Kobo using kepub books. |
![]() |
![]() |
![]() |
#15 | |||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,711
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Quote:
![]() Quote:
|
|||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
CSS Styling based on class/existing styling | 1ily | Calibre | 8 | 03-17-2025 06:37 AM |
Incorrect styling with specific CSS | quiris | Marvin | 9 | 07-04-2016 01:04 PM |
Missing CSS properties | roger64 | KOReader | 0 | 06-01-2016 06:39 AM |
inspect image properties /replace image | cybmole | Sigil | 6 | 02-05-2013 12:46 PM |
Unsetting properties in CSS | Jellby | ePub | 2 | 06-03-2009 04:29 AM |