Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTMLBody refuses to output the font size I specify, always ends up a different size

I'm trying to get my C# application to generate form emails. I should have had this wrapped up in an hour on Friday...but Outlook is being quite disobedient.

It seems that no matter the way I specify the font size in the MailItem's HTMLBody, it comes out a slightly different size. The Font face always comes out as specified, but the size is never right.

email.HTMLBody = "<p style='font-size:11px;font-family:Calibri;'>girl look at that body</p>";
email.HTMLBody = "<style> body { font-family:'Calibri'; font-size:11px; } </style> <body>girl look at that body</body>";
email.HTMLBody = "<html><header><style> body { font-family:'Calibri'; font-size:11px; } </style></header> <body>girl look at that body</body></html>";
email.HTMLBody = "<span style='font-size:11px;font-family:calibri;'>girl look at that body</span>";

produces size 8.5 font.

email.HTMLBody = "<html><body><font face='Calibri' size='11px'>girl look at that body</font></body></html>";
email.HTMLBody = "<font face='Calibri' size='11px'>girl look at that body</font>";

produces size 12 font.

So, it seems to be that specifying 11px (or 11pt, tried that too) font via CSS gets me 8.5px, and by font tags gets me 12px.

I've done a little further toying with this, and basically, the font tag produces 12pt font no matter what. So that's a dead end, but I knew the font tag was deprecated anyway. The CSS tag will give me different sizes, but rarely what I'm asking for. It's always off, and not by a consistent amount.

font-size in code = font-size in email:

  • 12 = 9
  • 13 = 10
  • 14 = 10.5
  • 15 = 11.5
  • 16 = 12
  • 17 = 13
  • 18 = 13.5
  • 19 = 14.5
  • 20 = 15

Specifying 14.5px in CSS gives me my desired 11px...but I don't feel comfortable deploying something that depends upon that.

What's the issue here? Is there something I'm neglecting to specify in CSS? Something I need to adjust elsewhere in MailItem, or Outlook.Application?

like image 488
friggle Avatar asked May 14 '12 16:05

friggle


People also ask

Why is my font size not changing in HTML?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.

What font size is 12px?

If the font-size you want is 12px , then you should specify 0.75em (because 12/16 = 0.75).


1 Answers

It is because you used 11px instead of pt. "px" stands for pixels, and 1 pixel size of text does not mean 1 point in font size. Use 11pt instead of 11px.

Per this discussion here: https://graphicdesign.stackexchange.com/questions/199/point-vs-pixel-what-is-the-difference

A pixel is a single square 'picture element' (hence pix-el), i.e. a single dot in your image. A 10x10 image is made up of a set of a set of pixels in a grid 10 wide by 10 deep, totalling 100 pixels.

The 'point' (pt) on the other hand is a unit of length, commonly used to measure the height of a font, but technically capable of measuring any length. In applications, 1pt is equal to exactly 1/72th of an inch; in traditional print technically 72pt is 0.996264 inches, although I think you'll be forgiven for rounding it up!

How many pixels = 1pt depends on the resolution of your image. If your image is 72ppi (pixels per inch), then one point will equal exactly one pixel.

like image 97
seekerOfKnowledge Avatar answered Oct 03 '22 19:10

seekerOfKnowledge