spacer
Yehuda Shiran October 16, 2001
Pixels to Inches Conversion
Tips: October 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
When you are dealing with page layout and document formatting, you need to be able to convert pixels to inches and vice versa. Suppose you get the margin specification in inches, and you need to format the page using the style object's pixel-based properties. One way to go about it is to set the location of an invisible marker in inches and then query its value in a script, yielding the same value in pixels. Let's see an example.

The following IMG tag defines an invisible marker, one inch away from the left edge of the window, and one inch below the top edge of the window:

<IMG ID="ratiomarker" CLASS="mmarker" STYLE="visibility:hidden;
 left:1in; top:1in; position: absolute" SRC="marker.gif" 
 WIDTH="15" HEIGHT="15" BORDER="0">

Click here to print the offset of ratiomarker. Since the invisible marker's offset is one inch in the IMG tag, the returned value offsetLeft is the conversion factor, pixels per inch. Also, notice that the marker style must be defined with absolute positioning.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends