![]() |
#1 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 70
Karma: 2119794
Join Date: Feb 2020
Location: Colorado
Device: Kobo Libra H20
|
Very basic ePub CSS?
I have some ePub files that I've downloaded from a free book site that I'm trying to clean up with a python script. Basically just some global search/replaces using regular expressions, and then replacing the CSS file with my own.
These will be loaded onto my Kobo Libra, converted to kepub, if that's relevant. Formatting in these files is extremely basic - chapters have a heading and paragraphs, seldom anything more. I'm looking for some basic guidelines to what works best on an ereader. Some specific questions: Default font size? Is 1em standard? What about line spacing? Should there be any page margins or padding? My Kobo has a (side) margin setting. If there's a standard, I'd want to use that and expect the Kobo's setting to work both with commercially published books and those that I modify. Paragraphs. Is there a standard for indents? I've seen 2em used. One thing I also notice in these files is that they specify two CSS files in the header. The first has most of the formatting. The second does nothing but set <body> top and bottom margins to 5pt. Is there any particular reason for doing this? |
![]() |
![]() |
![]() |
#2 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,771
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
What is this free eBook site and what is the eBook you've downloaded? I an grab a copy and have a look at the code.
As to defaults, there should be no font size set for the body font and there should be no margins and no line height (except if a large first letter or dropcap) is used. From your description of the second CSS file, it sounds like a Calibre conversion to ePub. |
![]() |
![]() |
![]() |
#3 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 70
Karma: 2119794
Join Date: Feb 2020
Location: Colorado
Device: Kobo Libra H20
|
Thanks. That's helpful. I'll see how that works.
Something else is that paragraphs are formatted as divs. <div class="p">..</div> My OCD is telling me to just change it all to <p>...</p> Is there any reason that paragraphs need to be <div>, or even <p> with a class designation? I can understand when a specific formatting is desired. If I don't specify the indent or treatment of paragraphs, will the ereader generally apply its own formatting, or just leave them without any indent at all? They'd still be block elements, but would anything set them off? |
![]() |
![]() |
![]() |
#4 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,771
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Normally <p> is used. I do convert those <div> to <p>. But you have to be careful as not all <div> would need to be converted. Some <div> may need to be left as a <div>.
As for indents, I prefer a 1.2em indent. I don't like paragraph spaces. Those are my personal preferences. |
![]() |
![]() |
![]() |
#5 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 316
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Quote:
|
|
![]() |
![]() |
![]() |
#6 |
mostly an observer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,519
Karma: 987654
Join Date: Dec 2012
Device: Kindle
|
Grab whatever you want from my style sheet, which is at https://notjohnkdp.blogspot.com/2013...yle-sheet.html
Or grab the whole thing, and when you're done use Sigil to get rid of the ones you don't use (Sigil > Tools > Delete Unused Style Classes. Save the streamlined style sheet and use it on subsequent books. |
![]() |
![]() |
![]() |
#7 |
Running with scissors
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,587
Karma: 14328510
Join Date: Nov 2019
Device: none
|
When I download an epub from Project Gutenberg I feel the need (compulsion) to "fix" its layout and formatting. I open it in Sigil, find the files that have the first and last chapters and use Sigil's merge function to turn them into one big file. Then I select and copy everything between the start and end body tags and paste that into a new Sigil instance, replacing that empty paragraph it provides. Looking at what that produces in Sigil's preview window it's by and large readable, the main offenders being a big space between paragraphs and no indentation; since I didn't copy over the original CSS file there's no styling other than what the previewer has built in.
So I'd start with something like that; strip all class= lines and make all the tags bare. Then add some basic css file after deleting the original. |
![]() |
![]() |
![]() |
#8 | |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,355
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:
I would recommend installing the cssRemoveUnusedSelectors plugin, It seems to do a great job, and prettify's your style sheet when it's done. Cheers, |
|
![]() |
![]() |
![]() |
#9 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,771
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#10 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,280
Karma: 169098402
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
I've found a couple of issues with calibre removing unused CSS elements. Multiple abcdefg::hijkl CSS3 pseudo-elements on the same line for one.
Last edited by DNSB; 06-17-2020 at 07:54 PM. |
![]() |
![]() |
![]() |
#11 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,532
Karma: 78910202
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
A few years ago Pablo made a basic tutorials on creating an ePub including a basic discussion of CSS. See https://www.mobileread.com/forums/sh...19#post1503619
|
![]() |
![]() |
![]() |
#12 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,771
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Any other issues? The good thing is that you can view the changes and see what's been removed and if something is removed that you don't want removed, you'll know it and can deal with it.
|
![]() |
![]() |
![]() |
#13 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,355
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
|
You can do that with the Sigil plugin as well. However, I haven't yet found a class that it has detected, or not detected, incorrectly.
|
![]() |
![]() |
![]() |
#14 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,771
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
![]() |
![]() |
![]() |
#15 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,355
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
|
True, but most of my books don't use that many different classes. I can usually remember the ones I have used and check to maker sure they are still there after the clean-up. I do a last minute look at all the pages in the book to make sure the styling still looks good. If I see a problem I revert back to the last saved version.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Basic CSS not working in Kindle iOS App | JohnnyW | Kindle Formats | 14 | 09-19-2014 07:10 PM |
Override ePub CSS with userStyle.css? | barium | Sony Reader Dev Corner | 11 | 07-16-2011 03:25 PM |
epub CSS versus "Regular" CSS | konrad | ePub | 4 | 02-18-2011 09:29 AM |
Basic CSS Font family question! | kjk | ePub | 2 | 05-27-2010 01:28 PM |
Basic CSS For Sony Reader | ExiledV20 | Sigil | 7 | 02-05-2010 02:38 AM |