Go Back   Dynamic Drive Forums > General Coding > CSS
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-25-2007, 06:48 AM
Girard Ibanez Girard Ibanez is offline
Regular Coders
 
Join Date: Jul 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paragraph / font size; proper technique

What is the proper / preferred method to change the font / paragraph looks.

In this example, I would like to change the default paragraph

<p> this text </p>


example1 = <p><span class="gray"> this text </span></p>

example2 = <p class="gray"> this text </p>



CSS style
.gray { font-size:1em; color: gray}

p.gray{ font-size:1em; color: gray}


thanks,

G
Reply With Quote
  #2  
Old 04-25-2007, 06:53 AM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

A span is for a segment within a paragraph.
For the whole paragraph, use <p>.
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #3  
Old 04-25-2007, 06:59 AM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,999
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

Both examples are correct. The second is more economical. However, it could need to be like in the first example if only some of the text in the paragraph needed that style. 1em is meaningless here. It would be the same as no font size specified. Font sizes really should be done as percents. This is not so much a matter of correctness as a matter of what works in the most browsers. 1em is 100% (also the same as not specifying).

If you have this:

Code:
.gray { font-size:1em; color: gray}
You don't need this:

Code:
p.gray{ font-size:1em; color: gray}
It really depends upon what you want. p.gray applies only to paragraphs. .gray can apply to any element.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #4  
Old 04-25-2007, 07:14 AM
codeexploiter's Avatar
codeexploiter codeexploiter is offline
Elite Coders
 
Join Date: Sep 2005
Location: India
Posts: 1,620
Thanks: 6
Thanked 104 Times in 104 Posts
Default

If you are looking for a method in which you have all the paragraph elements have a similar style without using a class upon them (it has its own disadvantages in all the other cases other than this) you can go for the following method

Code:
p { font-size:1em; color: gray}
This will apply the above mentioned style to all the paragraph elements you have in the page.

In the cases John explained you have more control over the style , you can decide on which paragraph you want to apply the style.
__________________
-Codex
http://jpvalappil.wordpress.com/
Reply With Quote
  #5  
Old 04-25-2007, 07:17 AM
Girard Ibanez Girard Ibanez is offline
Regular Coders
 
Join Date: Jul 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the clarification. I now understand the method and its purpose.




Girard
Reply With Quote
  #6  
Old 04-25-2007, 09:43 AM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

"Gray," however, is a poor choice for a class name. Class names should be semantic, not visual.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #7  
Old 04-26-2007, 03:17 AM
Girard Ibanez Girard Ibanez is offline
Regular Coders
 
Join Date: Jul 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
"Gray," however, is a poor choice for a class name. Class names should be semantic, not visual.
So if I wanted to change the <p> text size and color of the fonts what would be the best semantic way of organizing the style sheet? The more font size and colors can be very cluttered.

For example: If I had several pages and wanted different font sizes of a gray font, a red font ...etc.


Question 2:

If my divs are using ems as the width, and I my <p> tag is define for a font-size of 0.85em, what would be the best way to visually know what the size of the text would look like if I use a class tag with a font size of 0.75em?

From what I understand, defining the width using an em value will change the font size depending on the relationship of the child box (div). Still confuse on this one. I just like the way declaring em for the width zooms in portionally as the window shrinks or grows.


<div id="box">
<p> This text </p>
<p><span class="gray"> This text </span></p>

<div id="box2>
<p>This text </p>
<p><span class="gray"> This text </span></p>
</div>
</div>



<style>

#box1 {width: 50em}
#box2 {width: 50em}

p {font-size: 0.85em}
p.gray {font-size: 0.75em, color: gray;}

</style>
Reply With Quote
  #8  
Old 04-26-2007, 06:44 AM
nwalton nwalton is offline
Junior Coders
 
Join Date: Apr 2007
Location: Phoenix, AZ
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
what would be the best semantic way of organizing the style sheet?
The principle here is that the classes should be defined by their purpose, not by how they look. For instance, if the smaller gray text were meant as a caption, you would call it ".caption". Or if it were meant as a sub-head, you could even use an h3 or h4 instead of the span (that is, if everything in the block is meant to be small and gray, rather than just a portion of a paragraph).

Code:
<div id="box">
<p> This text </p>
<h3> This text </h3>
...
</div>

...
h3 { color:gray; font-size:0.75em;}

Quote:
If my divs are using ems as the width, and I my <p> tag is define for a font-size of 0.85em, what would be the best way to visually know what the size of the text would look like if I use a class tag with a font size of 0.75em?
An em is simply a measurement relative to the size of the font.

The default em size is usually 12px. If the <p> is defined as .85em, the font size ends up a little more than 10px. If you define another class tag, within that paragraph, at .75 em, it is measured relative to the size of the paragraph's font size (10px) not the default size (12px). It would end up being between 7px and 8px high (.75 of 10px).

Quote:
From what I understand, defining the width using an em value will change the font size depending on the relationship of the child box (div)
Defining the width of the <div> with an em value does not change the font size. It changes the width of the <div>, relative to the size of the font. So if I have a <div> that is 50em, the line lengths will be the same whether the font is 10em or .5em.


I hope that helps. I know it can get quite confusing sometimes.
Reply With Quote
  #9  
Old 04-26-2007, 11:18 AM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Quote:
The default em size is usually 12px. If the <p> is defined as .85em, the font size ends up a little more than 10px. If you define another class tag, within that paragraph, at .75 em, it is measured relative to the size of the paragraph's font size (10px) not the default size (12px). It would end up being between 7px and 8px high (.75 of 10px).
Well, in theory. Unfortunately, IE has a bug here and fails to calculate that, so we have to use percentages for font size instead.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #10  
Old 04-26-2007, 04:17 PM
nwalton nwalton is offline
Junior Coders
 
Join Date: Apr 2007
Location: Phoenix, AZ
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What doesn't break in IE....

So does IE not calculate ems at all, or is it just non-standard?
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:24 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.