04-05-2011, 06:12 PM | #1 | ||
Addict
Posts: 296
Karma: 955301
Join Date: Oct 2008
Device: Sony PRS-300, Sony PRS-T2, Kindle (7th Gen)
|
Applying multiple classes to an element
I am attempting to create a mobi format ebook by using kindlegen to convert an epub. I've managed to figure out the solution to most of the problems I've encountered, like preventing the cover appearing twice and adding guide items, but one problem has me stumped: it seems I can't apply multiple classes to an element.
So let's say this is an excerpt from my css file Code:
p.italic { font-style: italic; } p.bold { font-weight: bold; } And this is excerpt from the code in my xhtml file Code:
<p>Oh, do you know the muffin man,</p> <p class="italic">The muffin man, the muffin man,</p> <p class="bold">Do you know the muffin man,</p> <p class="italic bold">Who lives in Drury Lane?</p> My epub looks like this: Quote:
But when I convert that epub to a mobi, it looks like this! Quote:
Aaaaarrrgghh! Can I seriously not apply multiple classes to an element?! Damn you, Amazon, I don't want to be spending my time dealing with this idiocy. Epub Rules, Mobi Drools! There are obvious work arounds for this (just create a unique class like p.ihatemobi {font-style: italic; font-weight: bold;} ) but I'm hoping I'm wrong and you'll point out some comma or semi-colon I've missed out that will allow multiple classes |
||
04-05-2011, 08:06 PM | #2 |
Wizzard
Posts: 11,517
Karma: 33048258
Join Date: Mar 2010
Location: Roundworld
Device: Kindle 2 International, Sony PRS-T1, BlackBerry PlayBook, Acer Iconia
|
No, multiple classes do not work via KindleGen (unless this is one of the bugfixes for 1.2), and as you've noticed, it also completely ignores the first class used, which I think technically it should try to render under CSS fallback rules.
You also can't do descendant selectors, even the generic catchall type supported by CSS1, so if you want to style, say, all list items within a div of a certain class type (or even any div in general), you're going to have to mark up all those <li> or at least their containing <ol>/<ul> separately with target classes unless you're willing to have the style you want apply to everything within the parent <div> to save effort. Those are just two of the many ways in which KindleGen in particular and the Mobi format in general are made of fail, lose, and frustration. I say this from bitter personal experience. Hope this helps! |
Advert | |
|
04-05-2011, 08:34 PM | #3 | |
Addict
Posts: 296
Karma: 955301
Join Date: Oct 2008
Device: Sony PRS-300, Sony PRS-T2, Kindle (7th Gen)
|
Quote:
I know I could use Calibre to convert, but given that I have handcoded my precious epub, I want a bit more control over the behind-the-scenes code than Calibre will allow |
|
04-05-2011, 08:57 PM | #4 |
Wizzard
Posts: 11,517
Karma: 33048258
Join Date: Mar 2010
Location: Roundworld
Device: Kindle 2 International, Sony PRS-T1, BlackBerry PlayBook, Acer Iconia
|
It's a problem with KindleGen*. If you were to do your .ihatemobi class, it would work perfectly well as things can be styled multiple ways at once. You just can't have multiple separate class instructions for styling them so, at least not all on the same tag.
The only Mobi conversion tools that I'm aware of are
* Now, if you were to try and indent a right-hand margin and failed, that would be totally Mobi's fault… † Don't forget that newer versions of KindleGen add bloat in the form of the complete source files to your Mobi and you should use Kindlestrip to fix that. On the other hand, at least people would be able to admire your handcoding work? |
04-06-2011, 04:31 AM | #5 | |
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
I believe Calibre does some "CSS flattening" step in conversions, maybe you can convert your ePUB to ePUB (or something else) with Calibre, making sure the CSS is processed and flattened, and then convert to mobi with KindleGen or whatever.
Quote:
|
|
Advert | |
|
04-06-2011, 07:06 AM | #6 | |
Addict
Posts: 296
Karma: 955301
Join Date: Oct 2008
Device: Sony PRS-300, Sony PRS-T2, Kindle (7th Gen)
|
Quote:
I think I'll just have to make fat classes when I code my epubs. That will actually also solve the same problem I was having with the nasy, cheap, spare Binatone LCD eReader I have that runs FBReader. *sigh* Oh well, at least I've identified the problem, that's half the battle |
|
04-06-2011, 09:48 AM | #7 | |
Grand Sorcerer
Posts: 27,549
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
Now me and my sore head can take a new tack. |
|
04-06-2011, 11:44 AM | #8 |
Wizard
Posts: 2,251
Karma: 3720310
Join Date: Jan 2009
Location: USA
Device: Kindle, iPad (not used much for reading)
|
Why don't you try changing that line to use a single bold, italic class (both attributes), and see if that converts?
|
04-06-2011, 12:25 PM | #9 |
Addict
Posts: 296
Karma: 955301
Join Date: Oct 2008
Device: Sony PRS-300, Sony PRS-T2, Kindle (7th Gen)
|
Oh, it does (see the .ihatemobi class I mention in my first post). It's a legitimate workaround. But we shouldn't have to be finding workarounds, we should just be able to write code that complies with the W3C specs and have it bloody work
|
04-06-2011, 12:52 PM | #10 | |
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 |
|
04-06-2011, 01:23 PM | #11 | |
frumious Bandersnatch
Posts: 7,516
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
If you don't like Calibre output (which I understand), maybe you can find something else that just processes the CSS and "flattens" it. It's quite likely there are other legitimate CSS construct (selectors, precedence...) that confuse KindleGen, and flattening the CSS would be a desirable pre-convert step. |
|
04-06-2011, 02:53 PM | #12 |
Addict
Posts: 296
Karma: 955301
Join Date: Oct 2008
Device: Sony PRS-300, Sony PRS-T2, Kindle (7th Gen)
|
What makes me so cross is that Amazon insist in selling in mobi format. OK, fine. Their choice. But they specifically state that Kindlegen can "convert HTML, XHTML, XML (OPF/IDPF format), or ePub source into a Kindle Book."
The specs for HTML, ePub and the rest are available to them. The details of how mobi works are not available to us. The onus is on the people who insist on the black box format to make sure their conversion program can actually handle the input they claim it can, or to at the very least to describe what can't be converted. We, the users, shouldn't be forced to jam combination after combination through their meatgrinder to find out what does and doesn't work It's... it's... it's... it's just bloody rude, is what it is. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
keeping or removing a div with multiple classes | JohnsonZA | Recipes | 1 | 09-25-2010 10:33 AM |
iLiad Applying DR GTK+ patches to iLiad | ericshliao | iRex Developer's Corner | 16 | 03-14-2010 05:39 AM |
Amazon applying for in-book advertisement patent for Kindle | dreams | News | 57 | 07-13-2009 11:52 AM |
Applying Calibre recipes to a folder of pre-existing HTML files | MattK | Calibre | 3 | 09-24-2008 01:15 PM |
Applying hacks without flashing (brick save) | mkaluza | Sony Reader Dev Corner | 3 | 08-26-2008 04:45 AM |