|
|
#1 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 909
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
|
Am I Misunderstanding Nesting Selectors?
EDIT: OK. It looks like I don't need the actual & since I want the rule to apply to all descendents. If I pull it out, everyone's happy.
OP: I've got some CSS classes that are formatted as italic. If there's emphasized or italicized text inside those classes in a book, there's no visible difference from the rest of the text. After getting tired of trying to wrap such text with font-style: normal spans, I decided to try a nesting selector (&) in those classes to automatically apply the normal font-style when it runs into <i> and <em>. Here's an example: Code:
div.chapquote {
/* Chapter Quote (quote at top of chapters) Styling */
display: block;
font-style: italic;
margin-left: 1.5em;
margin-right: 1.5em;
padding-left: 1.5em;
padding-right: 1.5em;
text-align: justify;
& em {
font-style: normal;
}
& i {
font-style: normal;
}
}
Code:
ERROR CSS-008: An error occurred while parsing the CSS: Token "&" not allowed here. expecting a property name. Last edited by enuddleyarbl; Today at 03:19 PM. |
|
|
|
|
|
#2 |
|
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
& won't work in most cases. So don't use it. Most programs that handle ePub won't work with &.
|
|
|
|
|
|
#3 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 909
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
|
How should I go about getting <i> and <em> tagged text to be recognizable (in my case, font-style: normal) in text that is styled with an italicized CSS?
BTW: it turns out that if I remove the & in those styles, EpubCheck is happy with it being gone, but then complains about the {} bracketing the font-style:normal stuff. |
|
|
|
|
|
#4 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 909
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
|
I guess I could try pulling out the stuff the nesting selector was supposed to shortcut and adding it myself. In the above example, I think I'd add the following:
Code:
div.chapquote em {
font-style: normal;
}
div.chapquote i {
font-style: normal;
}
|
|
|
|
|
|
#5 | |
|
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
create a class such as... Code:
.normal {
font-style: normal;
}
Code:
(?s)(<p\b[^>]*class="[^"]*\bitalic\b[^"]*"[^>]*>(?:(?!</p>).)*?)<(i|em)\b[^>]*>(.*?)</\2> Code:
(?s)(<div\b[^>]*class=["'][^"']*\bitalic\b[^"']*["'][^>]*>(?:(?!</div>).)*?)<(i|em)\b[^>]*>(.*?)</\2> Code:
\1<span class="normal">\3</span> Last edited by JSWolf; Today at 04:40 PM. |
|
|
|
|
|
|
#6 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 909
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
|
I already have a "normal" class. I was initially replacing those <i> and <em> blocks with that. I don't want to do that (manually or with a regex). In those blocks of text that I've formatted with italicized CSS, I want any existing <i> and <em> "spans" to automatically display as "normal". I have a dozen or so classes that are italicized. I was trying to find a reasonable way to modify the CSS to do that.
Replacing all the nesting selectors in those classes with the separately broken out classes works, though it's ugly. But, now Calibre is complaining that those new classes near the bottom of my CSS are problematic because of "no-descending-specificity:" https://stylelint.io/user-guide/rule...g-specificity/ |
|
|
|
|
|
#7 |
|
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
This should be your CSS.
Code:
div.chapquote {
/* Chapter Quote (quote at top of chapters) Styling */
display: block;
font-style: italic;
margin-left: 1.5em;
margin-right: 1.5em;
}
.normal {
font-style: normal;
}
|
|
|
|
|
|
#8 | |
|
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CSS selectors | BobC | ePub | 6 | 02-07-2019 06:11 AM |
| EPUB and HTML Selectors | Rand Brittain | ePub | 2 | 03-06-2015 01:44 AM |
| HTML Tags and CSS Selectors | Doctor T | Kindle Formats | 3 | 10-26-2014 12:50 AM |
| Div Selectors vs Paragraph Classes -- Robustness? | GrannyGrump | ePub | 14 | 10-08-2013 09:49 AM |
| ADE support for attribute-value based selectors? | dmapr | ePub | 0 | 08-06-2010 06:57 PM |