![]() |
#1 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 769
Karma: 1537886
Join Date: Sep 2013
Device: Kobo Forma
|
Help with CSS for ePub3/HTML5 Tables?
I'm reformatting an old book in ePub3/HTML5. It has 6 tables that are defined with HTML using cellpadding and cellspacing (which are deprecated in HTML5). I'd like to get that into some CSS styles. Four of the 6 tables use:
- cellpadding="1" and - cellspacing="0". So, I guess those would be the default styles. One table uses: - cellpadding="4" and - cellspacing="0" and the last table uses: - cellpadding="5" and - cellspacing="5" I'm brand new to tables in css/html. But, I think for the "default" cellpadding="1", cellspacing="0" style, I'll need to set: table { border-spacing: 0px; } table, td, th { border-collapse: separate; } td, th { padding: 1px; } For the cellpadding="4", cellspacing="0" style, I think I'd need a style for setting td and th padding: 4px and for cellpadding="5", cellspacing="5" style, I'd need styles changing table border-spacing=5px and td, th padding:5px. Does that sound reasonable? And for my more basic question, how do I set up CSS classes/styles to handle the different versions? If I just needed to change the defaults, I could just list those things as above. But, how do I get them into multiple, separate, non-default classes/styles? |
![]() |
![]() |
![]() |
#2 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 769
Karma: 1537886
Join Date: Sep 2013
Device: Kobo Forma
|
Just a follow-up. After doing more research, I found that I could assign IDs to the tables and use those with # to apply the styles/classes to particular tables. I think I've got it working. The HTML for the table definitions used to look like:
Code:
<table cellpadding="4" cellspacing="0" style="width:100%" class="calibre18"> <colgroup class="calibre19"> <col style="width:50%" class="calibre20"/> <col style="width:50%" class="calibre20"/> </colgroup> <tbody class="calibre21"> <tr class="calibre22"> <td class="calibre23"> ... Code:
<table id="an3819"> <colgroup> <col/> <col/> </colgroup> <tbody> <tr> <td> ... Code:
table#an1111, table#an2315, table#an3477, table#an3819, table#an3988 { table-layout: fixed; width: 100%; border-spacing: 0; border: 1px black solid; } td { border-collapse: collapse; } table#an1111 td, table#an3477 td, table#an3988 td { width: 50%; border: 0; padding: 1px; vertical-align: top; } table#an2315 td { width: 50%; border: 0; padding: 0; vertical-align: top; } table#an3017 { table-layout: fixed; width: 100%; border-spacing: 5px; border: 1px black solid; } table#an3017 td { width: 50%; border: 0; padding: 5px; vertical-align: top; } td { border-collapse: separate; } table#an3819 td { width: 50%; border: 0; padding: 4px; vertical-align: top; } |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,312
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
|
Set your default table settings first, then set specific styles with a class:
Css: table { margin:….; border:….; etc. } table.pad1 { margin:….; padding:….; } table.pad2 { margin:….; padding:….; } Html: <table class="pad1"> Yadda, yadda </table> <table class="pad2"> Yadda, yadda </table> Edit: Ninja’d by the OP!! Lol IDs work too, but each ID has to be unique; you would have to give the CSS styling for EACH ID on your style sheet. With classes you can have multiples with the same styling … streamlined you CSS sheet. Last edited by Turtle91; 07-18-2022 at 01:12 PM. |
![]() |
![]() |
![]() |
#4 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,641
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
In epub2 is allowed to use for example: Code:
<table cellpadding="5" cellspacing="5" border="1"> <tbody> <tr> <td>Hi,</td> <td>how are you?</td> </tr> </tbody> </table> Code:
<table class="padspace" border="1"> <tbody> <tr> <td>Hi,</td> <td>how are you?</td> </tr> </tbody> </table> Code:
.padspace { border-spacing: 5px; border-collapse: separate; } .padspace td { padding: 5px; } Code:
<table class="padspace"> <tbody> <tr> <td>Hi,</td> <td>how are you?</td> </tr> </tbody> </table> Code:
.padspace { border: 3px solid black; border-spacing: 5px; border-collapse: separate; } .padspace td { border: 1px solid black; padding: 5px; } |
|
![]() |
![]() |
![]() |
#5 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 769
Karma: 1537886
Join Date: Sep 2013
Device: Kobo Forma
|
After playing around with the css formatting for those tables, I just set them all to the same settings. I don't know why the author/publisher made them slightly different from each other -- it really made no difference. In my stylesheet.css, I ended up with:
Code:
table#an1111, table#an2315, table#an3477, table#an3819, table#an3988, table#an3017 { table-layout: fixed; width: 100%; border-collapse: separate; border-spacing: 5px; border: 1px black solid; } table#an1111 td, table#an3477 td, table#an3988 td, table#an2315 td, table#an3017 td, table#an3819 td { width: 50%; border: 0; padding: 2px; } EDIT: After reading through RbnJrg's post, I noticed I had my border-collapse line in the td class instead of the table class. I moved it and changed my post, to reflect its new location. Last edited by enuddleyarbl; 07-18-2022 at 02:14 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,641
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Code:
.tabspace { table-layout: fixed; width: 100%; border-spacing: 5px; border-collapse: separate; border: 1px black solid; } .tabspace td { width: 50%; border: 0; padding: 2px; } |
|
![]() |
![]() |
![]() |
#7 | |||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
KISS. Keep It Simple, Stupid.
All you really need is:
For more info, see my posts in: Quote:
Then, tentatively, you can add more CSS on top of that if needed. Anyway, if you share an example image+HTML of your actual tables, we could make better judgements. - - - Side Note: If you want to make your tables more readable, you should also follow these basic rules:
If you want more info, I highly recommend reading my Posts #4, #9, and #11 in "Formatting tables best practices". Quote:
Quote:
Remember, ebooks can be read on very skinny/tall screens (like cellphones) with very large fonts. Personally, I minimize bloat as much as possible. Stick with the defaults, with very minor adjustments here and there. The most important thing is the proper HTML markup. That gets you 90% of the way there. This final 10% is niggling over smaller details. Last edited by Tex2002ans; 07-19-2022 at 05:58 PM. |
|||
![]() |
![]() |
![]() |
#8 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,136
Karma: 144284184
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
iBooks/Books is terrible on a small cell phone screen such as an iPhone with a 4.7" screen. The margins are way too large for the size of the screen. That eats a good chunk of the screen for no reason at all.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can KOReader read any html5, javascript and css code? | avnermoshkovitz | KOReader | 1 | 07-12-2021 06:55 AM |
Kindle for iPad - CSS for tables broken? | Oxford-eBooks | Kindle Formats | 35 | 04-06-2018 08:53 AM |
android pro quick guide apps: html5, CSS, regex... | cybmole | Sigil | 10 | 05-13-2014 02:11 AM |
Confused! XHTML, HTML, HTML5, EPUB2, EPUB3??? | carlosbcg | ePub | 29 | 02-23-2013 07:32 PM |
Tables in ePub: CSS | virtual_ink | ePub | 5 | 02-23-2012 02:51 PM |