![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
CSS 3 selector support in KF8
After reading PoP's post about his 2D Transforms tests support in KF8, I did some tests too and found out that KF8 actually supports the :first-letter selector even though the Kindle Publishing Guidelines say it doesn't
I used the following style to format the first letter of the first paragraph after the heading: Code:
p:nth-child(2):first-letter { font-family: sans-serif; float: left; font-size: 4em; font-weight: bold; margin-top: -0.2em; margin-bottom: -0.2em; margin-right: 5px; color: red; } tl:dr some CSS3 styles that have so far only been available in iBooks ePubs can also be used in KF8 books. EDIT: The following pseudo elements are known to work in KF8*: Code:
:after :before :first-letter :first-line :first-of-type :last-of-type :lang(xx) :nth-child(n) :nth-child(even) :nth-child(odd) :nth-of-type(n) :only-of-type :not Use at your own risk! Last edited by Doitsu; 03-30-2015 at 01:16 PM. Reason: updated title |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,339
Karma: 203719142
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Are you testing on real devices or Kindle Previewer?
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,339
Karma: 203719142
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Hmmm. I wonder what the reasoning is for explicitly stating it isn't supported, then? Does it do something unspeakable on the plain mobi side of the conversion? It's one thing to have undocumented support for something, but I would think there'd be a reason of some sort for expressly saying it's not supported.
Last edited by DiapDealer; 05-04-2013 at 08:24 AM. |
![]() |
![]() |
![]() |
#5 | |||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
OTOH, the publication guidelines also contains recommendations such as "Publishers can include their own font for their content. Amazon has a quality assurance process to ensure that these fonts display well on e Ink-based devices and do not impair the reading experience. Do not include the Charis font; it is replaced with a higher quality font in the Kindle Readers." I. e., whoever maintains the style guide might not be the most knowledgeable person. Quote:
![]() Quote:
![]() |
|||
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,339
Karma: 203719142
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
|
![]() |
![]() |
![]() |
#7 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,627
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Code:
p:nth-child(2):first-line { font-variant: small-caps; font-size:1.2em } p:nth-child(2):first-letter { float: left; font-size: 4em; font-weight: bold; margin-top: -0.2em; margin-bottom: -0.2em; margin-right: 5px; } Code:
p:first-line {text-transform: uppercase} ![]() ![]() |
|
![]() |
![]() |
![]() |
#8 | |
curly᷂͓̫̙᷊̥̮̾ͯͤͭͬͦͨ ʎʌɹnɔ
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,015
Karma: 50506927
Join Date: Dec 2010
Location: ♁ ᴺ₄₅°₃₀' ᵂ₇₃°₃₇' ±₆₀"
Device: K3₃.₄.₃ PW3&4₅.₁₃.₃
|
Quote:
Code:
h3:nth-child(2n) { font-family: sans-serif; font-size: 2em; text-align: center; text-transform: uppercase; text-shadow: 2px 2px 3px grey; transform: rotate(-3deg); -webkit-transform: rotate(-3deg); } h3:nth-child(2n+1) { font-family: sans-serif; font-size: 2em; text-align: center; text-transform: uppercase; text-shadow: 2px 2px 3px grey; transform: rotate(3deg); -webkit-transform: rotate(3deg); } /* paragraph immediately following heading3 */ h3 + p { text-indent: 0; } p { margin: 0; text-indent: 1em; } /* Small Caps RbnJrg: p:nth-child(2):first-line*/ h3 + p:first-line { font-variant: small-caps; font-size:1.2em; font-weight: bold; } /* Dropcaps Doitsu p:nth-child(2):first-letter */ h3 + p:first-letter { float: left; font-size: 4em; font-weight: bold; margin-top: -0.2em; margin-bottom: -0.2em; margin-right: 5px; } Thanks for digging more into this Doitsu and RbnJrg. Interesting, if not always reliable. My mileage did vary depending on devices. eReaders manufacturers must like that « The beauty with standards is that there are so many to choose from » ![]() Last edited by PoP; 05-06-2013 at 06:04 AM. Reason: define "chapter" |
|
![]() |
![]() |
![]() |
#9 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Apparently, KF8 supports quite a number of pseudo classes. I tested a couple more of them that I thought might be useful for automatically applying styles to unformatted paragraphs and found out that at least the following pseudo classes work:
:after :before :first-letter :first-line :first-of-type :last-of-type :lang(xx) :nth-child(n) :nth-child(even) :nth-child(odd) :nth-of-type(n) :only-of-type IMHO, some of them are redundant, while others provide useful automated formatting options. For example, you can use p:first-of-type:first-letter instead of explicitly selecting the paragraph by number with p:nth-child(2):first-letter to apply a dropcap style. You can also zebra-stripe table rows with :nth-child or insert text or images with :before and :after. (I've attached the updated epub, which passes epubcheck, compiles without warnings but doesn't work with ADE, to the first post.) Note that the text and symbols displayed in red in the KFPC screenshot have been created without modifying the .html file and without embedded fonts/images. Last edited by Doitsu; 05-06-2013 at 01:14 PM. |
![]() |
![]() |
![]() |
#10 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,627
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Amazon must have added support for them recently because I remember that not long ago I tried to use them and kindlegen gave me warning messages and not allow me to use them. Great work Doitsu!! |
|
![]() |
![]() |
![]() |
#11 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 8164
Join Date: Jul 2012
Device: Kindle Keyboard
|
Be very careful about making statements about what "KF8" supports. What you have discovered is what the version of webkit that is embedded in the device or app supports. That's important because there are subtle differences between the webkit versions on various KF8 capable devices and apps. I know there are differences in the types of media queries that work and I have no idea what other differences might exist.
|
![]() |
![]() |
![]() |
#12 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
I also made sure to only include pseudo classes that KindleGen 2.8 compiles without displaying warnings. For example, both the K3 and the Kindle for PC app also support :before with auto-incrementing counters just fine, however, since KindleGen 2.8 displayed a W28002: CSS style specified in content is not supported by Kindle readers. warning for them, I didn't include them. Just to be on the safe side, I also added a short disclaimer to my initial post. |
|
![]() |
![]() |
![]() |
#13 | |
Bookmaker & Cat Slave
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,503
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
|
Quote:
Actually, I'd note that in my opinion, K4PC is not one of the lowest common denominators. It displays some things (like the NCX) that aren't displayable on other Amazon "devices." I'd wonder if any of those would work in the Paperwhite, and, of course, with pseudo-classes like "first-letter" and child classes do you have any possibility of creating any fallback media queries for the earlier, K7 devices? Or, because K7 doesn't really "use" CSS, does any fallback coding get ignored? Just a question. (I mean, hell, last I looked, even Nook didn't support the pseudo-classes.) I'm very appreciative of the testing and the results! I'd love to use pseudo-classes and I'd really love to use the nth for table coloration, but...I think that would leave the K7 looking pretty damn barebones. We usually go to some lengths to ensure that we provide fallback styling for any K8 elements that won't "fly" on the K7, even to creating fallback styling for images that float in K8 but not in K7. I'd have to see if the fallback could indeed "fall back" and make something for the K7. Interesting. ![]() Hitch |
|
![]() |
![]() |
![]() |
#14 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 8164
Join Date: Jul 2012
Device: Kindle Keyboard
|
Hitch,
All these work on the Paperwhite. The Amazon e-Ink devices (excepting the old KF7 ones) have all been upgraded to a webkit build of 528 (possibly higher for the Paperwhite, I haven't checked since the last update). There's no way that I have found to precisely duplicate the ":first-line" pseudo class. I've taken to wrapping x words in a span (where x is a number between 4 and 8) and styling them inside a amzn-mobi media query). |
![]() |
![]() |
![]() |
#15 | |
Bookmaker & Cat Slave
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,503
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
|
Quote:
Hitch |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is the Kindle Keyboard (K3) ever going to get KF8 support? | apastuszak | Amazon Kindle | 25 | 12-05-2012 02:18 PM |
iPad Does Kindle App for iPad support KF8? | wiped | Apple Devices | 1 | 06-09-2012 01:44 PM |
KF8 and hyphenation support | pirl8 | Kindle Developer's Corner | 7 | 06-08-2012 10:59 AM |
KF8 conversion and support in Calibre? | Rhialto | Conversion | 19 | 01-16-2012 05:45 PM |
kf8 support | apastuszak | Calibre | 6 | 11-25-2011 09:22 PM |