Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 03-15-2025, 04:26 PM   #1
1ily
Connoisseur
1ily doesn't litter1ily doesn't litter
 
Posts: 61
Karma: 190
Join Date: Sep 2023
Device: Kobo Libra 2
CSS Styling based on class/existing styling

Hello!

I have a colour eink device, and it feels like the colour feature is going to a waste when most of my books are black and white.

I had the idea of adding colour to any div/p/span/header classes with a certain class or ID, but it misses the occasional text portion.

Is there any way to apply styling based on an existing class with the bold/italic styling?

Code:
h1, h2, h3, h4, h5, h6, i, em,div[class*="italic"],p[class*="italic"],span[class*="italic"], b, strong {
color: #8D4CF6;
}

span[class*="title"],p[id*="chapter"],div[id*="chapter"],span[id*="chapter"],p[id*="epilogue"],div[id*="epilogue"] ,span[id*="chapter"],span[id*="epilogue"],p[value*="Table of Contents"],p[value*="ToC"] ,div[value*="Table of Contents"],div[value*="ToC"],p[value*="prologue"] ,div[value*="prologue"],div[value*="prologue"] ,span[value*="prologue"] {
color: #8D4CF6;
}
1ily is offline   Reply With Quote
Old 03-15-2025, 06:40 PM   #2
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,604
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Where is that code snippet from? Is that your CSS code?
Karellen is online now   Reply With Quote
Old 03-15-2025, 10:25 PM   #3
1ily
Connoisseur
1ily doesn't litter1ily doesn't litter
 
Posts: 61
Karma: 190
Join Date: Sep 2023
Device: Kobo Libra 2
Quote:
Originally Posted by Karellen View Post
Where is that code snippet from? Is that your CSS code?
Yes, I made it myself. I put it in Preferences..Common options..Styling

It's not the cleanest thing in the world, but works in MOST cases. It misses any text portion where the class names are gibberish or ones that don't use the <i> or <b> tags. I'd like to change it and apply the color to all classes with a specific style attached to it or find another solution...

Last edited by 1ily; 03-15-2025 at 10:44 PM.
1ily is offline   Reply With Quote
Old 03-15-2025, 10:45 PM   #4
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,604
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Oh right. You are adding it in conversion, not actually editing the css in the ebook.

TBH, I have never fiddled with conversion settings as for me it is just easier to edit the css in the ebook.

So you are trying to colour the italic text.

If it were mine, I would change the <span class="italics"> to the correct <i> tags
Then I would create a css entry like this...

em, i, .italic {
font-style: italic;
color: #8D4CF6;
}

But if you still want to do that in conversion, others will need to advise you. But go ahead and try editing the css directly in a single ebook and see how it works out.
Karellen is online now   Reply With Quote
Old 03-15-2025, 10:46 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,171
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use the transform styles tool. There you can make rules like if the font-weight is bold add extra properties and so on
kovidgoyal is offline   Reply With Quote
Old 03-16-2025, 12:22 AM   #6
1ily
Connoisseur
1ily doesn't litter1ily doesn't litter
 
Posts: 61
Karma: 190
Join Date: Sep 2023
Device: Kobo Libra 2
Quote:
Originally Posted by Karellen View Post
Oh right. You are adding it in conversion, not actually editing the css in the ebook.

TBH, I have never fiddled with conversion settings as for me it is just easier to edit the css in the ebook.

So you are trying to colour the italic text.

If it were mine, I would change the <span class="italics"> to the correct <i> tags
Then I would create a css entry like this...

em, i, .italic {
font-style: italic;
color: #8D4CF6;
}

But if you still want to do that in conversion, others will need to advise you. But go ahead and try editing the css directly in a single ebook and see how it works out.
That is a good way to go about it, but I chose to do span[class*="italic"] because some of the class names have odd naming variations like "italic7", so the *= will catch any class name as long as "italic" somewhere inside it and apply the style!
1ily is offline   Reply With Quote
Old 03-16-2025, 12:23 AM   #7
1ily
Connoisseur
1ily doesn't litter1ily doesn't litter
 
Posts: 61
Karma: 190
Join Date: Sep 2023
Device: Kobo Libra 2
Quote:
Originally Posted by kovidgoyal View Post
Use the transform styles tool. There you can make rules like if the font-weight is bold add extra properties and so on
This is exactly what I was looking for. Thank you!
1ily is offline   Reply With Quote
Old 03-16-2025, 06:00 PM   #8
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,604
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by 1ily View Post
because some of the class names have odd naming variations like "italic7"
Great that you got it sorted out.
Though it does raise a side issue, why does your ebook need at least 7 italic classes? Something wrong there. Anyway just a bit of a worm to eat at you.
Karellen is online now   Reply With Quote
Old 03-17-2025, 06:37 AM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,029
Karma: 144284074
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by Karellen View Post
Great that you got it sorted out.
Though it does raise a side issue, why does your ebook need at least 7 italic classes? Something wrong there. Anyway just a bit of a worm to eat at you.
I've seen multiple italic classes for different reasons such as an embedded font or sans-serif or monospace, regular italic, bold italic, part of offset text so it has LR margins, etc.
JSWolf is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Styling book comments (description) with CSS tgiladi Library Management 26 11-24-2024 07:23 AM
Does converting to KFX format change or limit the CSS styling of the source file? jdunning Conversion 3 08-01-2019 10:35 PM
Incorrect styling with specific CSS quiris Marvin 9 07-04-2016 01:04 PM
Styling Elements in CSS - ADE and Sony toskpro Sony Reader 0 07-19-2010 01:55 PM
CSS Styling not showing up in digital editions sjkramer Sigil 9 01-30-2010 10:46 AM


All times are GMT -4. The time now is 01:30 AM.


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