Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old Today, 03:19 PM   #1
ElMiko
Evangelist
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: 473
Karma: 65460
Join Date: Jun 2011
Device: Kindle
Ordering css styling within a given class

Honestly, this seems like the first question I should have asked when I started doing this...

But does it matter what order styles appear within a given class?

Specifically I'm thinking about things like font-size and margins, but i'm sure there are other similar examples. If you're using em units, the height of a margin will scale based on the font size. But I thought that html is read top to bottom, so in theory the code

Code:
p {
font-size: 2em;
margin-top: 1em;
}
should look diffierent than

Code:
p {
margin-top: 1em;
font-size: 2em;
}
since the first case has a margin that is equal to one line of 2em text (as font-size has been previously established), whereas I would think that the second has a margin that equal to 1em text as it hasn't "read" that the text is supposed to be 2em yet, and by the time it does it's already defined the height of the margin.

But it appears that NOT what happens; they both tend to look the same. Am I misuderstanding the way top-to-bottom works in HTML?
ElMiko is online now   Reply With Quote
Old Today, 04:20 PM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,784
Karma: 169712580
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
As far as I understand, classes are evaluated top to bottom in the stylesheet but within a class, they are evaluated as a group. You may to take a look at how specificity is calculated.
DNSB is offline   Reply With Quote
Old Today, 04:36 PM   #3
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,915
Karma: 146918083
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
Honestly, this seems like the first question I should have asked when I started doing this...

But does it matter what order styles appear within a given class?

Specifically I'm thinking about things like font-size and margins, but i'm sure there are other similar examples. If you're using em units, the height of a margin will scale based on the font size. But I thought that html is read top to bottom, so in theory the code

Code:
p {
font-size: 2em;
margin-top: 1em;
}
should look diffierent than

Code:
p {
margin-top: 1em;
font-size: 2em;
}
since the first case has a margin that is equal to one line of 2em text (as font-size has been previously established), whereas I would think that the second has a margin that equal to 1em text as it hasn't "read" that the text is supposed to be 2em yet, and by the time it does it's already defined the height of the margin.

But it appears that NOT what happens; they both tend to look the same. Am I misuderstanding the way top-to-bottom works in HTML?
Both CSS are identical in what they do. CSS classes are read from top to bottom but in each class what's there is taken as a group.
JSWolf is offline   Reply With Quote
Old Today, 08:03 PM   #4
slm
Fool
slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.slm ought to be getting tired of karma fortunes by now.
 
Posts: 473
Karma: 4113712
Join Date: Feb 2003
Device: Kindle: Voyage,PW1,KOA, Kobo: Clara Colour, Nook GLP, Pocketbook verse
Changing font-size doesn't change the size of 1em. So your margin:1em line always has the same meaning, no matter what you do to font-size and no matter when it is read.
slm is offline   Reply With Quote
Old Today, 08:56 PM   #5
ElMiko
Evangelist
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: 473
Karma: 65460
Join Date: Jun 2011
Device: Kindle
@slm - Either I'm misunderstanding the intent of your post, or you are mistaken. Font-size does affect the size of the margin. The 1em of the margin will be in the context of the font-size. So, for example,

the margin in

Code:
p{
font-size: 2em;
margin-top: 1em;
}
will be twice as tall as the margin in

Code:
p{
font-size: 1em;
margin-top: 1em;
}
despite the margin value staying nominally the same.

@JSWolf, DNSB - Gotcha. So, witihin a class, margins and padding will always be derived from the font-size, even if the font size isn't technically declared until the "end" of the style list for that class? I'll see if i can unpack the specificity rules, but they may be over my head.
ElMiko is online now   Reply With Quote
Old Today, 10:18 PM   #6
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,784
Karma: 169712580
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Also remember if you nest font sizes, unless you specify them in rem (CSS3), the effect may not be quite what you are expecting.

That is if you have something like the following:
Code:
<h3 class="chapnum">Chapter number<br/><br/><span class="smallc">The End of All Dreams</span></h3>

.chapnum {
  font-size: 1.5em;
  margin-top: 2em;
  margin-bottom: 1.5em;
  page-break-after: avoid;
  text-align: center;
  font-weight: bold;
}


.smallc {
  font-size: 0.75em;
}
The first part will be have a font size of 2em and the second part in the span will have a font size of 2 x .75em or 1.5em.
DNSB is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image styling css... what do all these properties do? ElMiko Sigil 107 06-30-2025 05:16 PM
CSS Styling based on class/existing styling 1ily Calibre 8 03-17-2025 06:37 AM
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 11:13 PM.


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