Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 01:17 PM   #1
ElMiko
Fanatic
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 551
Karma: 65460
Join Date: Jun 2011
Device: Kindle Voyage, Boox Go 7
Selectively assigning font-size within an element

I am assuming this is a hard "No", but I figured I'd ask the pros anyway...

Is there a way—using css—to change the font-size of letters in an element, but not the font-size of punctuation or numbers?

Or is my only option to manually <span> out the letter strings and assign the font-size at that level?

(Normally, I would comfortably assume this is impossible, but you guys not-so-recently flagged properties like "text-align-last" which I would have imagined was so situation specific that it wouldn't exist... so here we are.)
ElMiko is offline   Reply With Quote
Old Yesterday, 01:43 PM   #2
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,474
Karma: 21000001
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Traditionally it required the use of spans… which is very frustrating seeing a very large opening quote with the large initial drop cap.

I think renderer’s simply choose to include punctuation in the :first-letter pseudo-element.

I’m not aware of a :first-symbol ???
Turtle91 is offline   Reply With Quote
Advert
Old Yesterday, 02:01 PM   #3
icearch
Zealot
icearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheese
 
Posts: 121
Karma: 1000
Join Date: Nov 2025
Device: none
Think another way around: edit the font file.
(which is more tedious and require pro tools and knowledge)
icearch is offline   Reply With Quote
Old Yesterday, 02:05 PM   #4
icearch
Zealot
icearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheese
 
Posts: 121
Karma: 1000
Join Date: Nov 2025
Device: none
To be serious, this level/depth of formatting control kinna kills the whole premises of re-flowable file isn't it?
icearch is offline   Reply With Quote
Old Yesterday, 02:09 PM   #5
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: 82,670
Karma: 151278869
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 icearch View Post
To be serious, this level/depth of formatting control kinna kills the whole premises of re-flowable file isn't it?
No it doesn't kill the premise of reflowable. It just means that to get what you want, you'd need to use an embedded font that's been edited to do what you want.
JSWolf is offline   Reply With Quote
Advert
Old Yesterday, 04:30 PM   #6
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,930
Karma: 9553607
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by ElMiko View Post

Is there a way—using css—to change the font-size of letters in an element, but not the font-size of punctuation or numbers?
Yes, of course, but under epub3 (and with no custom font nor spans). You need to employ the following code:

1. In your xhtml file:

Code:
  
   <p class="MyFont">Lorem ipsum dolor March 29, 2026 sit amet, consectetur adipiscing elit. Nulla ac tellus nunc. Phasellus imperdiet leo metus, et gravida lacus. Donec metus ligula, elementum at pellentesque pellentesque, suscipit ac nunc.</p>
2. In you .css file:

Code:
@font-face {
    font-family: "MyTimes";
    src: local("Times New Roman"); 
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "MyTimes";
    src: local("Times New Roman");
    unicode-range: U+0030-0039, U+0021-002F, U+003A-0040, U+005B-0060, U+007B-007E;   
    size-adjust: 150%; /* Here you set the size you wish */
}

.MyFont {
    font-family: "MyTimes";
    line-height: 1.2em;
}
Here you have how it looks under Readium:

Click image for larger version

Name:	Readium.png
Views:	14
Size:	62.4 KB
ID:	222188

With this method (you must define twice the @font-face declaration, the first one is the fallback code for the whole unicode-range), you don't need an special font. In my example I employed a local font ("Times New Roman") but if you wish, you can incluye your custom font in the epub and in that case, you need to replace:

Code:
    src: local("Times New Roman");
with:

Code:
    src: url("../Fonts/YourFont.ttf");
Of course, also you can use an .otf font. Also, don't use 150% for the size of numbers; I included that figure so you can watch better how the method works, but a size 110% it would be ok.

The unicode-range method is extremely flexible because it allows you to segment the font by any "block" of characters you wish to treat independently, such as uppercase letters, thus providing another way to achieve raised caps and drop caps.

To make uppercase letters larger, you only need to define the Unicode range corresponding to the capital letters of the Latin alphabet.

Last edited by RbnJrg; Yesterday at 04:43 PM.
RbnJrg is offline   Reply With Quote
Old Yesterday, 04:47 PM   #7
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,930
Karma: 9553607
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by JSWolf View Post
No it doesn't kill the premise of reflowable. It just means that to get what you want, you'd need to use an embedded font that's been edited to do what you want.
That only for old ereaders; with modern ones, you can use the method I posted previously; another advantage of epub3 over epub2.
RbnJrg is offline   Reply With Quote
Old Yesterday, 04:49 PM   #8
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,930
Karma: 9553607
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by icearch View Post
Think another way around: edit the font file.
(which is more tedious and require pro tools and knowledge)
Under epub3 that is no longer necessary.
RbnJrg is offline   Reply With Quote
Old Yesterday, 04:58 PM   #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: 82,670
Karma: 151278869
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 RbnJrg View Post
That only for old ereaders; with modern ones, you can use the method I posted previously; another advantage of epub3 over epub2.
But again, that's not backwards compatible. So if you are trying to be backwards compatible, go for the spans.

The problem with ePub is that you cannot be sure the person reading will be doing so with an ePub3 program.
JSWolf is offline   Reply With Quote
Old Yesterday, 08:25 PM   #10
ElMiko
Fanatic
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 551
Karma: 65460
Join Date: Jun 2011
Device: Kindle Voyage, Boox Go 7
Thanks, all.

@RbnJrg - This is interesting. As I'm doing all my reading in KOReader these days, I try to be cautious about how advanced I get with my css as I know that KOR is not fully epub3 compatible (something I know you lament). But your elegant solution still gives me lots of food for thought.

@icereach - I don't see how this would negatively affect the reflowability of the document(any more than selectively changed relative font sizes currently does, like THIS)...

Last edited by ElMiko; Yesterday at 08:30 PM.
ElMiko is offline   Reply With Quote
Old Yesterday, 08:44 PM   #11
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,474
Karma: 21000001
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Despite some individual’s willful ignorance of the concept of fall-back coding, you can code for both ePub 2 and 3 in the same ePub. It takes a little more work, but it works. You can use all the new techniques to give your customers the best possible product if their device supports it and a good product if they don’t.

Take a look at:
css hierarchy rules
@supports
@media
Scripts

You can also search here since there are several threads discussing fall-back coding.

Cheers!
Turtle91 is offline   Reply With Quote
Old Yesterday, 09:03 PM   #12
ElMiko
Fanatic
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 551
Karma: 65460
Join Date: Jun 2011
Device: Kindle Voyage, Boox Go 7
Thanks, @Turtle91, I'll do that. In this case, however, it seems that the fall back coding would have to be <span>ing the desired text anyway, at which point the elegant epub3 solution becomes visually redundant.

But your point is well-taken, and there are certainly other situations where two slightly different treatments (one that makes it looks great, and one that makes it look acceptable) could be called for.
ElMiko is offline   Reply With Quote
Old Yesterday, 09:24 PM   #13
icearch
Zealot
icearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheeseicearch can extract oil from cheese
 
Posts: 121
Karma: 1000
Join Date: Nov 2025
Device: none
Quote:
Originally Posted by ElMiko View Post
Thanks, all.

@RbnJrg - This is interesting. As I'm doing all my reading in KOReader these days, I try to be cautious about how advanced I get with my css as I know that KOR is not fully epub3 compatible (something I know you lament). But your elegant solution still gives me lots of food for thought.

@icereach - I don't see how this would negatively affect the reflowability of the document(any more than selectively changed relative font sizes currently does, like THIS)...
I was just joking around, nevermind.
icearch is offline   Reply With Quote
Old Yesterday, 09:49 PM   #14
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,930
Karma: 9553607
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by ElMiko View Post
Thanks, all.

@RbnJrg - This is interesting. As I'm doing all my reading in KOReader these days, I try to be cautious about how advanced I get with my css as I know that KOR is not fully epub3 compatible (something I know you lament). But your elegant solution still gives me lots of food for thought.
No, the method doesn't work on KOReader; you need an ereader based on Chromiun/Webkit/Readium and KR is based on CoolReader
RbnJrg is offline   Reply With Quote
Old Today, 08:41 AM   #15
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: 82,670
Karma: 151278869
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 ElMiko View Post
Thanks, @Turtle91, I'll do that. In this case, however, it seems that the fall back coding would have to be <span>ing the desired text anyway, at which point the elegant epub3 solution becomes visually redundant.

But your point is well-taken, and there are certainly other situations where two slightly different treatments (one that makes it looks great, and one that makes it look acceptable) could be called for.
But in this case, it can look the same. It just means the ePub3 solution is not going to be as simple. However, the solution that would work for both ePub2 and ePub3 actually is better as it would not rely on any embedded font.

It just mean you have to use spans which will work in more cases then the embedded font solution.
JSWolf is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moon+ Reader your favorite font and font size? loodio Android Devices 6 01-30-2016 06:50 PM
Problem changing font size using font size key Waylander Conversion 0 10-02-2013 03:30 PM
Determine font and font size on incoming epub? peaceridge Calibre 4 01-30-2012 03:35 PM
PRS-300 Med font size too big, but small font size too small eli2k Sony Reader 4 05-28-2010 09:47 AM


All times are GMT -4. The time now is 10:56 AM.


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