![]() |
![]() ![]() |
![]() |
Woody20 |
![]()
Post
#1
|
Novice ![]() ![]() Group: Members Posts: 27 Joined: 11-March 11 Member No.: 14,105 ![]() |
I have an unusual question, arising from a pgm which reads RTF and outputs HTML.
The pgm is outputting HTML like CODE <style> .jus{ text-align: justify; } .sz10{ font-size: 10pt; } .sz17{ font-size: 17pt; } .f0{ font-family: Times New Roman, Times, serif; } .f32{ font-family: Verdana, sans-serif; } </style> <p class="f0 sz17 cl1 jus sz10" style="text-indent: 12pt;"> <span class="f32">Some sample text</span> The intent is that "Some sample text" is 10-point Verdana, but it appears as 17-point. It looks like the <p> class gives the first definition of font-size (i e sz17) precedence over the second (sz10). What I want to know is, is there a rule for which size will take precedence (first, last, or something else)? And is this rule, if there is one, standard HTML, or different among browsers? A related question: would the same rule apply for other attributes (e g, font-family, justify vs left, etc)? |
Darin McGrew |
![]()
Post
#2
|
WDG Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 8,266 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 ![]() |
The p element has 2 font-size properties. The two selectors have the same specificity, so the one specified later wins. Since the rule for the .sz17 selector appears after the rule for the .sz10 selector, the rule for the .sz17 selector wins.
Is there a reason to include both the sz10 and sz17 class? Only one can have any affect, so you should just omit the unused one. See also: http://www.w3.org/TR/CSS2/cascade.html#cascading-order |
Woody20 |
![]()
Post
#3
|
Novice ![]() ![]() Group: Members Posts: 27 Joined: 11-March 11 Member No.: 14,105 ![]() |
Is there a reason to include both the sz10 and sz17 class? Only one can have any affect, so you should just omit the unused one. |
Darin McGrew |
![]()
Post
#4
|
WDG Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 8,266 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 ![]() |
QUOTE What is desired is for the one appearing later in the class to dominate Yeah, CSS doesn't work that way. The order the classes appear in the class attribute is irrelevant. It's the order the selectors appear in the style sheet(s) that matters. |
Christian J |
![]()
Post
#5
|
. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 7,787 Joined: 10-August 06 Member No.: 7 ![]() |
You might give the first rule higher specificity with the !important keyword:
CODE .sz10{ font-size: 10pt !important; } .sz17{ font-size: 17pt; } or by adding the element selector to the rule: CODE p.sz10{ font-size: 10pt; } .sz17{ font-size: 17pt; } BTW, the pt unit is meant for printed media. For screen font sizes you should use percent or em. (This used to matter in older browsers, don't know if there are still any practical consequences of using pt with screen media.) |
pandy |
![]()
Post
#6
|
Don't like donuts. Don't do MySpace. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 17,883 Joined: 9-August 06 Member No.: 6 ![]() |
If editing the style sheet is a workable option it would be enough to reorder the rules. But I guess it isn't always the same class that is desired to take precedence. If it's is, this is pretty much a non-issue.
|
Christian J |
![]()
Post
#7
|
. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 7,787 Joined: 10-August 06 Member No.: 7 ![]() |
Sorry, misunderstood!
|
pandy |
![]()
Post
#8
|
Don't like donuts. Don't do MySpace. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 17,883 Joined: 9-August 06 Member No.: 6 ![]() |
I don't know. I'm just guessing.
![]() |
![]() ![]() |
![]() |
Lo-Fi Version | Time is now: 19th April 2018 - 02:26 PM |