Thread: CSS selectors
View Single Post
Old 02-04-2019, 08:15 PM   #3
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,834
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by BobC View Post
I'm looking to find a way of using a css selector with some unusual parameters.

I'm familiar with using a selector such as

Code:
p + p {
text-indent: 2em;
}
or
Code:
p.class1 + p {
text-align : right;
}
however what I'm looking for is one which will only select the second <p> where the first one has no class declared; i.e it won't select in the case of say

Code:
<p class="caption"> blah, blah, blah </p>
<p> some more text </p>
Or any other "classed" <p> tag.

I'm not sure if this is possible - has anyone found a way of doing this.

BobC
I don't understand very well your example but it seems that you are looking for the :nth-child() selector. In your case:

1. In the .css stylesheet:

Code:
p:nth-child(2) {
  background: yellow;
}
2. In the .xhtml file:

Code:
<p>The first paragraph.</p>
<p>The second paragraph.</p>  /* the style will only be applied to this paragraph */
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
The issue here is that the :nth-child() selector it won't be supported by ADE under epub2 (however Kindle with .kf8 will accept it).
RbnJrg is offline   Reply With Quote