![]() |
#1 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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; } Code:
p { margin-top: 1em; font-size: 2em; } 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? |
![]() |
![]() |
![]() |
#2 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#3 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
|
|
![]() |
![]() |
![]() |
#4 |
Fool
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#5 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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; } Code:
p{ font-size: 1em; margin-top: 1em; } @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. |
![]() |
![]() |
![]() |
#6 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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; } |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |