Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 01-06-2016, 11:28 AM   #1
Macsurfcat
Enthusiast
Macsurfcat began at the beginning.
 
Posts: 29
Karma: 10
Join Date: Apr 2013
Location: New Jersey
Device: Kindle, Nook
Pseudo classes with classes

I would like to select the first instance of a classed element (eg: <p class="attribution">) in a sequence of same classed elements for differential styling via a CSS:

<p class="attribution"> Harry Summers</p>
<p class="attribution">King of Heartland</p>
<p class="attribution">Companion to the Queen</p>

I've tried "first-of-type" but with no luck.
Macsurfcat is offline   Reply With Quote
Old 01-06-2016, 11:43 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,516
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
I think :first-of-type is only CSS3 (and it would target the first <p>, provided it has a given class, not the "first p with a given class", I believe), so don't expect ePub 2 renderers to support it.

Maybe you can invert the selection. "p.attribution + p.attribution" would target the second and later of the series, which you could use to "cancel" the style you asign to "p.attribution".

But, the best is probably adding an additional class:

Code:
<p class="attribution first"> Harry Summers</p>
<p class="attribution">King of Heartland</p>
<p class="attribution">Companion to the Queen</p>
and then use "p.attribution.first"
Jellby is offline   Reply With Quote
Advert
Old 01-06-2016, 02:52 PM   #3
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,263
Karma: 74007256
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
How about
Code:
.attribution {  background-color: red;}
.attribution + .attribution {    background-color: green;}
PeterT is offline   Reply With Quote
Old 01-06-2016, 04:09 PM   #4
Macsurfcat
Enthusiast
Macsurfcat began at the beginning.
 
Posts: 29
Karma: 10
Join Date: Apr 2013
Location: New Jersey
Device: Kindle, Nook
yes, have suggested adding another class, "first", that would solve all any and all problems, but I really like the reversal.
Macsurfcat is offline   Reply With Quote
Old 01-07-2016, 04:00 AM   #5
dgatwood
Curmudgeon
dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.
 
dgatwood's Avatar
 
Posts: 629
Karma: 1623086
Join Date: Jan 2012
Device: iPad, iPhone, Nook Simple Touch
Quote:
Originally Posted by Jellby View Post
I think :first-of-type is only CSS3 (and it would target the first <p>, provided it has a given class, not the "first p with a given class", I believe), so don't expect ePub 2 renderers to support it.
CSS4 offers :nth-match(). I wouldn't expect any reader to support it yet, though iBooks might support it in 10.11/iOS 9 and later if they've whitelisted it and if support made it into WebKit in time for that release. (I haven't tried.)

I think the syntax would be something like:

Code:
p:nth-match(0n+1 of .bar) {
...
}
but don't quote me on that.

With that said, either the next sibling operator (PeterT's suggestion) or the generic sibling selector will probably work, depending on whether you want the first matching paragraph after any non-matching paragraph to be formatted like the first matching paragraph. If you don't, then do something like this instead:

Code:
.attribution {  background-color: red;}
.attribution ~ .attribution {    background-color: green;}
dgatwood is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple classes compatibility senhal ePub 5 11-23-2015 08:00 PM
Aura HD Micro SD Card - All about Classes xibalban Kobo Reader 7 09-18-2014 11:49 AM
Classes in CSS in recipes? Tegan Recipes 10 01-17-2011 07:30 PM


All times are GMT -4. The time now is 01:22 PM.


MobileRead.com is a privately owned, operated and funded community.