Web Design Forum: Different font sizes for different font families in CSS? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Different font sizes for different font families in CSS?

#1 User is offline   Mody 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 47
  • Joined: 03-February 08
  • Reputation: 0
  • Location:Spain
  • Experience:Beginner
  • Area of Expertise:Entrepreneur

Posted 21 March 2008 - 02:02 PM

Hi everybody,

I hope you are doing great. I am really liking the the new Calibri font that comes with Windows Vista and I wanted to know if it is possible to set a different font size depending on the font to be displayed. Calibri looks good and readable in my opinion at 14px, but Arial (my second choice) is just too large at 14px. Calibri at any smaller size than 14px is too small and is not readable. Is there anyway I can set 14px for those who have Calibri installed and a different font size for those who have Arial in my CSS? I don't think it exists but I thought I can ask.

Thanks for your help. :)
0

#2 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 21 March 2008 - 02:08 PM

Unfortunatly no. Webdesigners doesn't have much control over types.
You'll have to find a different fallback font, such as Tahoma.
0

#3 User is offline   Mody 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 47
  • Joined: 03-February 08
  • Reputation: 0
  • Location:Spain
  • Experience:Beginner
  • Area of Expertise:Entrepreneur

Posted 21 March 2008 - 02:30 PM

View PostThomas Thomassen, on Mar 21 2008, 15:08, said:

Unfortunatly no. Webdesigners doesn't have much control over types.
You'll have to find a different fallback font, such as Tahoma.


So it's official now. :(

Thanks for the quick reply Thomas, I really appreciate it. Have a great day!
0

#4 User is offline   Rob 

  • Web Design Rawkes!
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,210
  • Joined: 27-February 08
  • Reputation: 22
  • Gender:Male
  • Location:Bournemouth, UK
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 21 March 2008 - 02:45 PM

That is a very interesting issue you've brought up Mody, I'm pretty sure that functionality doesn't exist at the moment in CSS 2.1
0

#5 User is offline   Sono Juventino 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 368
  • Joined: 17-March 08
  • Reputation: 0
  • Gender:Male
  • Location:Oslo, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 23 March 2008 - 12:21 AM

I think you should take a look at sIFR. It's not for huge blocks of text, but it can be nice on headings as an example. In that way, you will be able to use your beloved Calibri-font. :)
0

#6 User is offline   Mody 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 47
  • Joined: 03-February 08
  • Reputation: 0
  • Location:Spain
  • Experience:Beginner
  • Area of Expertise:Entrepreneur

Posted 03 April 2008 - 07:09 PM

View PostSono Juventino, on Mar 23 2008, 00:21, said:

I think you should take a look at sIFR. It's not for huge blocks of text, but it can be nice on headings as an example. In that way, you will be able to use your beloved Calibri-font. :)


Sorry about the (very) late reply, I have completely forgotten this thread. I do know of sIFR, but as you said, it is only useful for headings and small blocks of text. I was hoping that it could be done with CSS but there is no way.

Thanks for trying to help and sorry again for the very late reply.
0

#7 User is offline   Subhajit 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 330
  • Joined: 27-March 08
  • Reputation: 0
  • Location:India - Kolkata
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 07:24 PM

Hey Mody..

Nice topic Bro... as said by the Rob above that till now there is no options in CSS 2.1, I too appreciate it.
But one thing struck on my mind that if its possible detect the Font ( whether it is installed in the system or not) with the help of some script, then switch between two class. The two classes will have the property of font-family and font-size.

I would request all of you to focus on this and reply whether its possible or not. :unsure:
0

#8 User is offline   Sono Juventino 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 368
  • Joined: 17-March 08
  • Reputation: 0
  • Gender:Male
  • Location:Oslo, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 07:46 PM

This might be possible with php or some other language.

if font = arial {
print "font-size: 14px;"
}

if font = colibri {
print "font-size: 16px;"
}

else { font-size: 100%; }

Or something. :p

I'm not familiar with php, but I think you understand.
0

#9 User is offline   Subhajit 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 330
  • Joined: 27-March 08
  • Reputation: 0
  • Location:India - Kolkata
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 07:51 PM

View PostSono Juventino, on Apr 4 2008, 01:16, said:

This might be possible with php or some other language.

if font = arial {
print "font-size: 14px;"
}

if font = colibri {
print "font-size: 16px;"
}

else { font-size: 100%; }

Or something. :p

I'm not familiar with php, but I think you understand.


Thaks for your Quick Reply... Sono :)
I would request some of the Coders to check this and reply if this can be utilised.

Any other suggessions are always appreciated... :)
0

#10 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 08:05 PM

Nopes. PHP is a server side script. It won't have access to the clients computer. It's no go I'm afraid.
0

#11 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 08:12 PM

Basically, typography in CSS is not very controllable. The best you can do is make suggestions to how you prefer it.

Your best option would be to pick one or more websafe fonts that have similar characteristics as Calibri as alternative fonts. Remember, some users override the font size any way, making them large, or in some rare cases smaller.

Do you use anti-aliasing? I find Calibri perfectly clear and readable down to 10px before it starts to become somewhat harder. Certainly not any less readable than any other common type. I use ClearType for anti-aliasin though. That might affect readability.
0

#12 User is offline   Subhajit 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 330
  • Joined: 27-March 08
  • Reputation: 0
  • Location:India - Kolkata
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 08:13 PM

View PostThomas Thomassen, on Apr 4 2008, 01:35, said:

Nopes. PHP is a server side script. It won't have access to the clients computer. It's no go I'm afraid.


Thanks for your reply Bro Thomas :)

Is it possible with Client Side Scripting, may be javascript ???
0

#13 User is offline   Mody 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 47
  • Joined: 03-February 08
  • Reputation: 0
  • Location:Spain
  • Experience:Beginner
  • Area of Expertise:Entrepreneur

Posted 03 April 2008 - 09:23 PM

View PostThomas Thomassen, on Apr 3 2008, 20:12, said:

Basically, typography in CSS is not very controllable. The best you can do is make suggestions to how you prefer it.

Your best option would be to pick one or more websafe fonts that have similar characteristics as Calibri as alternative fonts. Remember, some users override the font size any way, making them large, or in some rare cases smaller.

Do you use anti-aliasing? I find Calibri perfectly clear and readable down to 10px before it starts to become somewhat harder. Certainly not any less readable than any other common type. I use ClearType for anti-aliasin though. That might affect readability.


Hi Thomas. I just decided not to use it. Calibri is actually readable down to 12px in my opinion (I misused the word readable in my first post), but to my liking it looks good at 14px. However, it is certainly smaller than fonts like Arial at similar sizes. Way smaller actually.

This is not an issue for me anymore. I learned to live with it. :) It would be interesting to know if there is a method to do it though.
0

#14 User is offline   Aaron Russell 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 115
  • Joined: 25-March 08
  • Reputation: 0
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 03 April 2008 - 09:54 PM

It can be done with Javascript but it is a faff. Basically Javascript cant just check if a user has a font installed by itself as that would be a security flaw, so you have to do the following:

Create two 'test' DIVS with the same text in each - one with a standard font and one with calibri as the main font, followed by the same standard font as backup if calibri is not installed. Then you use javascript to return the width of each of the test DIVS (using offsetwidth). If the widths are not the same then the test is true and the client has the font installed. If the widths are the same, then the test is false and you can use javascript to dynamically change the font size.

So, it can be done... but like I said it's a bit of a faff.

(ps - it still works if the test divs are set to visabillity:hidden so the user can't see them)
0

#15 User is offline   Mody 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 47
  • Joined: 03-February 08
  • Reputation: 0
  • Location:Spain
  • Experience:Beginner
  • Area of Expertise:Entrepreneur

Posted 04 April 2008 - 08:29 PM

View PostAaron Russell, on Apr 3 2008, 21:54, said:

It can be done with Javascript but it is a faff. Basically Javascript cant just check if a user has a font installed by itself as that would be a security flaw, so you have to do the following:

Create two 'test' DIVS with the same text in each - one with a standard font and one with calibri as the main font, followed by the same standard font as backup if calibri is not installed. Then you use javascript to return the width of each of the test DIVS (using offsetwidth). If the widths are not the same then the test is true and the client has the font installed. If the widths are the same, then the test is false and you can use javascript to dynamically change the font size.

So, it can be done... but like I said it's a bit of a faff.

(ps - it still works if the test divs are set to visabillity:hidden so the user can't see them)


Thanks Aaron, that's very interesting. I myself would not use it but it can be useful to others.

(PS: Your website is beautiful. Great work!)
0

#16 User is offline   Subhajit 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 330
  • Joined: 27-March 08
  • Reputation: 0
  • Location:India - Kolkata
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 05 April 2008 - 05:11 AM

View PostAaron Russell, on Apr 4 2008, 03:24, said:

It can be done with Javascript but it is a faff. Basically Javascript cant just check if a user has a font installed by itself as that would be a security flaw, so you have to do the following:

Create two 'test' DIVS with the same text in each - one with a standard font and one with calibri as the main font, followed by the same standard font as backup if calibri is not installed. Then you use javascript to return the width of each of the test DIVS (using offsetwidth). If the widths are not the same then the test is true and the client has the font installed. If the widths are the same, then the test is false and you can use javascript to dynamically change the font size.

So, it can be done... but like I said it's a bit of a faff.

(ps - it still works if the test divs are set to visabillity:hidden so the user can't see them)


Thanks for your great suggession Bro..
I am really very much interested in doing this, but problem is I don't have so much knowledge in Javascript.
Can you help me out by providing a code if time provides you ?
It would be very much helpful for me..

Thanks once again... :)
0

#17 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 06 April 2008 - 12:11 PM

View PostSubhajit, on Apr 5 2008, 07:11, said:

Thanks for your great suggession Bro..
I am really very much interested in doing this, but problem is I don't have so much knowledge in Javascript.
Can you help me out by providing a code if time provides you ?
It would be very much helpful for me..

Thanks once again... :)


Not tested, just writing down from the top of my head:

// Call this function when the document loads. Preferably when the DOM has loaded.
function adjustFontSize()
{
	// Create test element
	var sandbox = document.createElement('div');
	var customFontDiv = document.createElement('div');
	var compareDiv = document.createElement('div');
	
	// Set their font
	// Ensure they are not visible
	// Position the container absolutely so they do not affect the page flow
	// Float the test elements to make them shrink wrap to the content
	with (sandbox.style)
	{
		visibility = 'hidden';
		position = 'absolute';
	}
	
	with (customFontDiv.style)
	{
		fontFamily = 'Calibri, Arial';
		float = 'left';
	}
	
	with (compareDiv.style)
	{
		fontFamily = 'Arial';
		float = 'left';
	}
	
	// Add some content to the test elements
	customFontDiv.appendChild( document.createTextNode('Lorem ipsum dolor sit amet') );
	compareDiv.appendChild( document.createTextNode('Lorem ipsum dolor sit amet') );
	
	// Connect the elements together and add them to the document
	sandbox.appendChild( customFontDiv );
	sandbox.appendChild( compareDiv );
	document.body.appendChild( sandbox );

	// Get the test element's width and compare them
	if (customFontDiv.clientWidth !== compareDiv.clientWidth)
	{
		// The two test elements doesn't have the same width so we can assume that
		// Calibri has been used. Now we adjust as we see fit.
		document.body.style.fontSize = '14px';
	}
	else
	{
		// The test elements have identical width, Calibri might not have been used.
		// (!) Note that two fonts might retun identical width to the divs, so you have
		//	 to check first which font to use for comparison. Remember you will
		//	 have to pick a 'web safe' font.
		document.body.style.fontSize = '12px';
	}
}

0

#18 User is offline   Aaron Russell 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 115
  • Joined: 25-March 08
  • Reputation: 0
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 06 April 2008 - 07:46 PM

Looks like a good bit of code Thomas - thumbs up from me!
0

#19 User is offline   Subhajit 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 330
  • Joined: 27-March 08
  • Reputation: 0
  • Location:India - Kolkata
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 06 April 2008 - 08:17 PM

View PostThomas Thomassen, on Apr 6 2008, 17:41, said:

Not tested, just writing down from the top of my head:

// Call this function when the document loads. Preferably when the DOM has loaded.
function adjustFontSize()
{
	// Create test element
	var sandbox = document.createElement('div');
	var customFontDiv = document.createElement('div');
	var compareDiv = document.createElement('div');
	
	// Set their font
	// Ensure they are not visible
	// Position the container absolutely so they do not affect the page flow
	// Float the test elements to make them shrink wrap to the content
	with (sandbox.style)
	{
		visibility = 'hidden';
		position = 'absolute';
	}
	
	with (customFontDiv.style)
	{
		fontFamily = 'Calibri, Arial';
		float = 'left';
	}
	
	with (compareDiv.style)
	{
		fontFamily = 'Arial';
		float = 'left';
	}
	
	// Add some content to the test elements
	customFontDiv.appendChild( document.createTextNode('Lorem ipsum dolor sit amet') );
	compareDiv.appendChild( document.createTextNode('Lorem ipsum dolor sit amet') );
	
	// Connect the elements together and add them to the document
	sandbox.appendChild( customFontDiv );
	sandbox.appendChild( compareDiv );
	document.body.appendChild( sandbox );

	// Get the test element's width and compare them
	if (customFontDiv.clientWidth !== compareDiv.clientWidth)
	{
		// The two test elements doesn't have the same width so we can assume that
		// Calibri has been used. Now we adjust as we see fit.
		document.body.style.fontSize = '14px';
	}
	else
	{
		// The test elements have identical width, Calibri might not have been used.
		// (!) Note that two fonts might retun identical width to the divs, so you have
		//	 to check first which font to use for comparison. Remember you will
		//	 have to pick a 'web safe' font.
		document.body.style.fontSize = '12px';
	}
}


Thank you very much... Thomas :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users