The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Precedence for font-size attribute in a class?
Woody20
post Mar 13 2012, 12:39 AM
Post #1


Novice
**

Group: Members
Posts: 24
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)?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Mar 13 2012, 02:34 AM
Post #2


WDG Member
********

Group: Root Admin
Posts: 8,017
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


--------------------
Darin McGrew
WDG Member since 1998
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Woody20
post Mar 13 2012, 12:45 PM
Post #3


Novice
**

Group: Members
Posts: 24
Joined: 11-March 11
Member No.: 14,105



QUOTE(Darin McGrew @ Mar 13 2012, 02:34 AM) *

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.
The output is being produced by a pgm, not a person. What is desired is for the one appearing later in the class to dominate, so I guess I will have to add code to remove the earlier, undesired one from the list.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Mar 13 2012, 12:53 PM
Post #4


WDG Member
********

Group: Root Admin
Posts: 8,017
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.


--------------------
Darin McGrew
WDG Member since 1998
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 13 2012, 02:09 PM
Post #5


.
********

Group: WDG Moderators
Posts: 6,139
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.)


--------------------
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 13 2012, 02:37 PM
Post #6


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 15,549
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.


--------------------
"Never go to excess, but let moderation be your guide."
- Cicero

IPB Image
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 13 2012, 03:38 PM
Post #7


.
********

Group: WDG Moderators
Posts: 6,139
Joined: 10-August 06
Member No.: 7



Sorry, misunderstood!


--------------------
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 13 2012, 03:54 PM
Post #8


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 15,549
Joined: 9-August 06
Member No.: 6



I don't know. I'm just guessing. blush.gif


--------------------
"Never go to excess, but let moderation be your guide."
- Cicero

IPB Image
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 22nd October 2014 - 06:55 PM