PHP Classes

Howto calculate dimensions of a HTML element?

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  Howto calculate dimensions of a HTML...  
Subject:Howto calculate dimensions of a HTML...
Summary:If we write a string into a HTML element, how can we ...
Messages:15
Author:Nico den Boer
Date:2009-10-06 06:21:35
Update:2009-10-07 07:41:48
 

  1. Howto calculate dimensions of a HTML...   Reply   Report abuse  
Picture of Nico den Boer Nico den Boer - 2009-10-06 06:21:36
If we write a string into a HTML element, how can we then determine the final required height of an object?

Example:
$msg = "Hello,
This is an email from me with some text for you. This is an email from me with some text for you. This is an email from me with some text for you. This is an email from me with some text for you.

I do have something to say, but ... cannot find the right words :)
";

PHP script line:
echo "<div style\"width: 200px;\">$msg</div>";

In this example string, I have pressed enter a few times. You can also (probably) see the wordwrap. The div elemenent has a fixed width, but no fixed height. Within the div, my text will wrap.

The big question is, how can I beforehand determine in this case what the final height of the element will become after it is rendered in the browser?

Of course we know which font we use, which size, which style (plan, bold, italic, underlined).

It seems to be a typographical question, but, PHP programmers will need to answer it sometimes. For me, I face the question for the first time and don't know how to answer it (yet). Your help will be appreciated ...

Kind regards,
Nico

There are 14 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.