02-04-2019, 03:32 PM | #1 |
Guru
Posts: 691
Karma: 3026110
Join Date: Dec 2008
Location: Lancashire, U.K.
Device: BeBook 1, BeBook Pure, Kobo Glo, (and HD),Energy Sistem EReader Pro +
|
CSS selectors
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; } Code:
p.class1 + p { text-align : right; } Code:
<p class="caption"> blah, blah, blah </p> <p> some more text </p> I'm not sure if this is possible - has anyone found a way of doing this. BobC |
02-04-2019, 03:58 PM | #2 |
Grand Sorcerer
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Theoretically, you could use a :not() pseudo selector for this. For example:
Code:
p:not([class]) + p { color: red; } |
02-04-2019, 08:15 PM | #3 | |
Wizard
Posts: 1,539
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
1. In the .css stylesheet: Code:
p:nth-child(2) { background: yellow; } 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> |
|
02-06-2019, 04:48 AM | #4 |
Guru
Posts: 691
Karma: 3026110
Join Date: Dec 2008
Location: Lancashire, U.K.
Device: BeBook 1, BeBook Pure, Kobo Glo, (and HD),Energy Sistem EReader Pro +
|
@Doitsu
The not pseudo class seems to be what I was after, however with its limited support I doubt if I will be using it. @RbnJrg I don't think your solution would work, the second paragraph isn't a "child" of the first, it's just a successor and would be selected by P + P. In any case with the limited support I wouldn't want to use it. It's not a big problem anyway - I was just looking for a lazy way to catch some exceptions to the general rule. I'll continue with my original method where I need to invert the logic and specify the classes for the initial p using something like : Code:
p { text-indent : 2em; } p.class1 + p, p.class2 + p, p.class3 + p { text-indent : 0; } BobC |
02-06-2019, 06:22 AM | #5 | |
Wizard
Posts: 1,539
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
And never a <p> tag can be a "child" of another <p> tag. It would be a successor, but not a child. Thouse tags are "childs" of <body> or, if it's present, a <div> tag. For example: Code:
<div> <p>This is the first paragraph and the first child of div</p> <p>This is the second paragraph, the second child of div</p> </div> Code:
p[id ~= my_id] + p { text-indent: 0; } Code:
<p id="my_id 1">This is the first paragraph</p> <p>This is the second paragraph</p> /* This one won't be indented */ ... ... <p id="my_id 2">This is the first paragraph</p> <p>This is the second paragraph</p> /* This one won't be indented */ So, instead of using: Code:
<p class="class1">blah, blah, blah</p> <p>blah, blah, blah</p> Code:
<p id="my_id 1">blah, blah, blah</p> <p>blah, blah, blah</p> Code:
p.class1 + p, p.class2 + p, p.class3 + p { text-indent: 0; } Code:
p[id ~= my_id] + p { text-indent: 0; } Code:
p[title ~= my_title] + p { text-indent: 0; } Code:
<p title="my_title 1">blah, blah, blah</p> <p>blah, blah, blah</p> With the selector "p[title ~= my_title] + p", you are going to select all <p> tags that are successors of another <p> tag with a title attribute containing the word "my_title". Last edited by RbnJrg; 02-06-2019 at 06:45 AM. |
|
02-06-2019, 05:19 PM | #6 |
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
BobC, may I ask what the exact use-case is?
Give a concrete example of what you're trying to emulate. I think that'll make it a bit easier to understand what the issue is, and if there's any other potential ways of tackling the problem. |
02-07-2019, 05:11 AM | #7 | |
Guru
Posts: 691
Karma: 3026110
Join Date: Dec 2008
Location: Lancashire, U.K.
Device: BeBook 1, BeBook Pure, Kobo Glo, (and HD),Energy Sistem EReader Pro +
|
Quote:
Again thanks to all who have offered ideas - I've picked up some from @RbnJrg's examples that will come in useful in other situations. BobC |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
EPUB and HTML Selectors | Rand Brittain | ePub | 2 | 03-06-2015 12:44 AM |
HTML Tags and CSS Selectors | Doctor T | Kindle Formats | 3 | 10-25-2014 11:50 PM |
Div Selectors vs Paragraph Classes -- Robustness? | GrannyGrump | ePub | 14 | 10-08-2013 08:49 AM |
css pseudo elements and adjacent combinators in extra css? | ldolse | Calibre | 2 | 12-21-2010 05:09 PM |
ADE support for attribute-value based selectors? | dmapr | ePub | 0 | 08-06-2010 05:57 PM |