473,583 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

font-size question

I have a <pelement with <ttinside:

;;; <p>A paragraph contains <tt>tt element</tt>.</p>

I would like to set the font-size of the TT to the same
as the containing <p>.

This does not seem to work:

;;; p {
;;; font-size: medium;
;;; }
;;;
;;; p tt {
;;; font-size: 100%;
;;; }

when default sizes for propertional and monospace fonts
are set to different values in a browser.

Is there a way to achieve the goal without resorting to
'px'?

TIA
T.
Jan 16 '07 #1
30 4513
Scripsit Takehiko Abe:
I have a <pelement with <ttinside:
- -
I would like to set the font-size of the TT to the same
as the containing <p>.
That would be
p tt { font-size: 100%; }
or, equivalently by the specifications,
p tt { font-size: 1em; }
This does not seem to work:

;;; p {
;;; font-size: medium;
;;; }
The font size of the p element is irrelevant for the purposes of the stated
problem, except if you used physical units like px or mm, and you shouldn't
use them.

Besides, this particular setting, which uses medium as font-size value, is
not recommendable, since its effect depends on the browser. Even on IE 7,
you get different results depending on "standards mode" vs. "quirks mode".
;;; p tt {
;;; font-size: 100%;
;;; }
What do you mean by saying that it does not work? Note that the visual
appearance of a monospace font may give the impression of increased font
size. This may sound self-contradictory to most people, since most people do
not know what "font size" really means.

Letters are generally larger (taller) in a monospace font than in a
proportional font of the same size. This is probably the main reason why
many browsers use reduced font size for elements that are usually rendered
in a monospace font, so that the effect might correspond to something like
tt, code, samp, pre, textarea { font-size: 90% }. You can see whether this
is the case in your browser by using
tt, code, samp, pre, textarea { font-family: Times New Roman; }

Similarly, you can test test whether
p tt { font-size: 100%; }
takes effect, if you add the rule
p, p tt { font-family: Times New Roman; }
(You could use just p tt { font-family: inherit; }, but IE doesn't support
it.)
when default sizes for propertional and monospace fonts
are set to different values in a browser.
Unless there's some bad browser bug involved, those default sizes should
have no effect when font-size is set. In theory, browser settings _might_
conceptually map to CSS rules with !important specifier, but I don't think
things are that way, and if they are, there's nothing you can do about it as
an author - !important is _meant_ to be the user's last resort and give him
the final word.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jan 16 '07 #2
;;; p tt {
;;; font-size: 100%;
;;; }

What do you mean by saying that it does not work?
What I meant is that TT rendered with different font-size than P.
For instance, in my FireFox (2.0) sans-serif font is set to
"Helvetica 14" and monospace to "Courier 13". With these
defaults and the above CSS style, it appears that P is
rendered with Helvetica 14 and TT with Courier 13.
Letters are generally larger (taller) in a monospace font than in a
proportional font of the same size. This is probably the main reason why
many browsers use reduced font size for elements that are usually rendered
in a monospace font, so that the effect might correspond to something like
tt, code, samp, pre, textarea { font-size: 90% }. You can see whether this
is the case in your browser by using
tt, code, samp, pre, textarea { font-family: Times New Roman; }
I tested with "tt { font-family: sans-serif}" (I assumed that this
provides the same test as your example). TT is rendered with
"Helvetica 14" (the default in my browser.)

(I am using HTML 4.01 strict.)

Thanks,
T.
Jan 16 '07 #3
VK

Takehiko Abe wrote:
I have a <pelement with <ttinside:

;;; <p>A paragraph contains <tt>tt element</tt>.</p>

I would like to set the font-size of the TT to the same
as the containing <p>.

This does not seem to work:

;;; p {
;;; font-size: medium;
;;; }
;;;
;;; p tt {
;;; font-size: 100%;
;;; }
Sure it does.
when default sizes for propertional and monospace fonts
are set to different values in a browser.
No they are not: but they give different _visual_ effect because their
glyphs are build on different principles.
Is there a way to achieve the goal without resorting to 'px'?
That is irrelevant what are you using: all relative units are
calculated into pixel values before being applied. In this aspect is
irrelevant what are you using: %, em, ex, pt, or anything else: the
actual style on the screen will be always in px.
What _is_ important that relative units are being recalculated for each
partucular hardware and current text size settings.

You can easily check that both fonts have the font-size in px:

<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
p {
font-size: 2em;
}
p tt {
font-size: 1em;
}
</style>
<script type="text/javascript">
function init() {
var P = document.getEle mentsByTagName( 'p')[0];
var T = document.getEle mentsByTagName( 'tt')[0];
if (document.defau ltView) {
alert(
document.defaul tView.getComput edStyle(P,'firs t-letter').fontSi ze );
alert(
document.defaul tView.getComput edStyle(T,'firs t-letter').fontSi ze );
}
}
window.onload = init;
</script>
</head>
<body>
<p>Text<tt>Text </tt></p>
</body>
</html>

It is also easy to check that they are on the same baseline. So
whatever was required is accomplished. If you want a _visual_ equality
of serif and monospace then you have to break their physical equality
by making either one smaller or bigger: naturally the adjustment effect
may differ by hardware configurations.

Jan 16 '07 #4
"VK" wrote:
No they are not:
You mean the two are the same?

Unless I am missing something, they are different _px_ in my
browsers on my hardware right now.
>
You can easily check that both fonts have the font-size in px:
[...]
Since I use FireFox, I don't need Javascript to check the
computed font sizes. And they are different.
Jan 16 '07 #5
VK

Takehiko Abe wrote:
"VK" wrote:
No they are not:

You mean the two are the same?
Yes. I mean physical size, not the look.
Unless I am missing something, they are different _px_ in my
browsers on my hardware right now.
That is the optical illusion I mentioned in my previous post. This is
why I provided JavaScript code in my sample. Run it and you will see
that both <Pand <TTblocks have the same px size. Without knowing
the DPI value on your current hardware, I cannot tell for sure what
number will it be. For 96DPI with default Text Size setting it will be
32px. All I can say that both values will be the same no matter what.
If you think that the program is cheating on you :-) then make a
screenshot and paste into any image editing program. Mesure the height
of say "e" letter in both blocks.
Since I use FireFox, I don't need Javascript to check the
computed font sizes. And they are different.
That is an allusion: they are the same. As I explained earlier, you
have a choice as with any optical illusion: leave physical equality but
live then with visual difference - or break physical equality but get
the visual one.

Jan 16 '07 #6
That is the optical illusion I mentioned in my previous post.

What I'm seeing is _certainly_ not an optical illusion.
This is
why I provided JavaScript code in my sample. Run it and you will see
that both <Pand <TTblocks have the same px size.
Just run it and it gave me 28px and 26px respectively.
Jan 16 '07 #7
VK

Takehiko Abe wrote:
This is
why I provided JavaScript code in my sample. Run it and you will see
that both <Pand <TTblocks have the same px size.

Just run it and it gave me 28px and 26px respectively.
OK, then I can tell two things for sure:

1) Your hardware uses 72DPI instead of 96DPI, so with 99% guarantee in
is not Windows. As you name makes me think of Japan, my first bet is on
MacOS

2) In your current browser monospace fonts are preset to be shown
smaller than variable width fonts to make them visually of the same
size. As I explained earlier it cannot be done without breaking
physical equality - and it is "pre-broken" on your browser.

The latter pretty much takes the problem out of the common CSS
techniques topics. You may ask for advise at <comp.sys.mac.s ystem>

Jan 16 '07 #8
VK schrieb:
Takehiko Abe wrote:
>>This is
why I provided JavaScript code in my sample. Run it and you will see
that both <Pand <TTblocks have the same px size.
Just run it and it gave me 28px and 26px respectively.

OK, then I can tell two things for sure:

1) Your hardware uses 72DPI instead of 96DPI, so with 99% guarantee in
is not Windows. As you name makes me think of Japan, my first bet is on
MacOS
I ran your test file on Firefox 1.5.0.9 (Windows, 96dpi), sans-serif:
14px, monospace: 13px.

Result: 28px, 26px.

--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jan 16 '07 #9
2) In your current browser monospace fonts are preset to be shown
smaller than variable width fonts
No.
Jan 16 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4160
by: Justin Van Patten | last post by:
Hello, I am having trouble converting a LOGFONT structure to a System.Drawing.Font object. I'm calling SystemParametersInfo to get the LOGFONT lfntSMCaptionFont from a NONCLIENTMETRICS structure. I seem to be doing this correctly, but when I try to create a System.Drawing.Font object with the Font.FromLogFont, the new Font object has a...
10
4039
by: Richard R Plourde | last post by:
I've got a problem that IE doesn't seem to use the entire font unicode subgroups from a hinted font file. When I display the following web page in IE 6 as opposed to Firefox 1.0 PR. Check out the web page in question... http://clientserver.home.comcast.net/unicode.html If you examine, for a few examples, characters such as square root...
3
26549
by: Wim | last post by:
I would like to store the ListView font in the XML config file. So I have a string variable listFont that stores the font (font.ToString()). It must be a string variable because a Font object cannot be written to the XML config file. Next time the program is started the font is read from the config file. But how to convert the string to a Font...
3
3653
by: pnp | last post by:
I have created a coposite user control of a text box and a label. I have exposed the font of the textbox property through a property of the control but every time I try to change that through the property grid of the designer when I use the composite control in a form, after a rebuild the changes seem to get lost! I don't see the Font property...
6
1913
by: ryan.mclean | last post by:
Hi all! I was hoping someone could help me out. What I would like to do is use a font that is not installed on the server, but does reside in my local web. Does that make sense? I would like to take the responsibility off the server administrator and put it back on the developers. I realize I may be asking for the impossible, but any...
4
1933
by: BobAchgill | last post by:
Is it possible to use a font that is not stored in the windows font directory? I would like to use a font that is stored in my application directory... But this does not seem to work... rtbMyRichTextBox.SelectionFont = New Font(CurDir() + "\" + "MyFont.ttf", 12, FontStyle.Bold) Thanks!
6
8086
by: BobAchgill | last post by:
Has anyone had success with writing text using a private font that was not already installed to the system? When I try the example code in NET Framework Developer's Guide called “Creating a Private Font Collection” .... I only see a default font written to the form NOT the private font that was loaded. Ofcourse I see the right font...
1
2717
by: Henry Jones | last post by:
I found some code to change the font on a button to bold: private void btnBold_Click(object sender, System.EventArgs e) { btnCalculate.Font = new Font(btnCalculate.Font, btnCalculate.Font.Style | FontStyle.Bold);
24
2825
by: Tony Girgenti | last post by:
Hello. Developing a Windows Form program in VS.NET VB, .NET Framework 1.1.4322 on a windows XP Pro, SP2. Before printing a document, i want to set the font to a font that is only available with the printer that i am printing to(Zebra TLP2844). When i open Word and look at the fonts available for the default printer, it does not show...
16
1863
by: carlbernardi | last post by:
Hi, I was wondering if there is way use a font that is somehow kept in the code instead of having to load it? I am working on a single script that so far can produce images and html but I have not been able to figure out a way that it can also produce a font. Thanks Carl
0
7894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3814
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.