views:

45

answers:

4

I've just gotten into web development seriously, and I'm trying to make a page that appears the same physical size ( in inches ) across all browsers and platforms I believe a combination of percentage values and inch values can make a consistent UI.

my own system is a 15.4 inch screen with 1920x1200 pixels i.e. 144 DPI.

Here is the most simple HTML code that fails to appear the right size on any browser except FireFox (Tried on Chrome 3, 4, Opera 10.5, IE7)

<html><head>
<body>
<div 
style="position:absolute; width:2in; height:1in;   border:1px solid" > 
hello world</div>
</body></html>

Chrome, Opera and IE render a .67 inch box ( They seem to be assuming a 96 DPI screen )

I am running Windows XP, but I see no reason why that would make a difference. Similar incorrect rendering on other machines I have tested.

I thought when I say "1in" in HTML it means one actual inch in the real world....

How do I handle this?

Thanks in advance, Vivek

Edit :

in 2006 I developed an activex control which did live video editing for a website, in 2008 we started seeing lots of Vista use and higher DPI screens which made the UI unusable, I reworked the application so that everything scaled according to DPI, since then everyones happy that they don't need glasses to use the feature....

The whole reason that Win7 and Vista have this "DPI scaling" mode is to allow non-DPI aware apps to display ( but since it basically scales up the app's canvas, the apps look blurry ).

I can't believe that calling GetDeviceCaps() or the X-Windows equivalent is harder than hardcoding 96 DPI. Anyway it wouldnt affect any page that measures in pixels....

A: 

I don't really think you can, to be honest.

The DPI of the screen is determined in hardware, i.e. a 15.4" Screen with 1920x1080 resolution = 144DPI.

Why do you need the site to appear as the same physical dimensions? Surely the same size, proportional to the screen is enough? i.e. if my resolution is 1920x1080, your site should take up 50% of the wide. If I'm using 1600x1050, it should take up 60%?

Jamie
+1  A: 

Instead of giving the size in px you just give it in percentage . so that it can fit on any screen based on the percentage .

karthi_ms
A: 

In short — you can't, at least for use on screen.

Using real world units depends on having clients knowing the correct DPI for the system. Between clients that don't bother, and systems which are not configured correctly, it is a hopeless situation.

If you want something to scale so it is a reasonable size for the users system, then you are likely best off using em units to scale based on the user's font size. This still has problems where the defaults are not suitable and the user hasn't changed them, but it is right more often than physical units.

David Dorward
+2  A: 

Can't be done. Period.

Screens are a grid of pixels and that is the only unit recognized by the physical display. Any other measurement must be converted to pixels for display.

This conversion is done by the operating system's graphics subsystem, which has an internal "DPI" setting - quoted because it's arbitrary and does not necessarily correspond to the actual physical DPI of any real-world device. Windows, for example, defaults to 96 DPI regardless of the display that it's connected to.

When you look at a page with something with a height of "1in", your machine looks at it, calculates that, since it's set for 144 DPI, "1in" means 144 pixels and makes it 144 pixels tall, regardless of the physical distance that those 144 pixels will occupy on your display.

When the typical Windows user with the default 96 DPI setting looks at it, their computer calculates that "1in" = 96px and makes it 96 pixels tall, again regardless of the physical distance that will correspond to those 96 pixels.

And you know what? This is a good thing. It means that a user with poor vision can lower their video driver's DPI setting and everything sized in inches, cm, point, em, or other 'real-world' units (i.e., basically anything other than percent or pixels) will get bigger so that they can see it more easily. Conversely, those of us who don't mind small text can artificially increase our DPI settings to shrink it all and get more onto our screens.

The tyranny of the printed page, forcing things to be a certain size whether we like it or not, is no more. Embrace the power this gives your users over their experience. Don't try to take that away - you won't succeed and you'll just annoy people in the process.

Dave Sherohman
Windows does default to 96 DPI but one can set it to anything on the Display Properties.I write a lot of native applications, I detect the DPI of the system (as defined by windows) and scale my GUI and fonts.I think all browsers should do the same, The point I'm making is that Firefox does this! Other browsers don't - On my system 8 point text is too small to read, if web pages specified in inches, then I wouldn't have to zoom them. the GetDeviceCaps() API retrieves the user supplied DPI, so is it so hard to use that value instead of a hardcoded 96?
rep_movsd
And as for the tyranny of fixed sizes - A 40 pixel high textbox, which looks normal on my system would look positively hideous on 96 DPIEven If i did specify it in percent, a label which is 2% of my screenheight will look oversized on lower DPI systems...How would you like to see nice 16 pt text as default, just because thats the legible size on my system.If a user wants bigger size, there's the zoom functionality available on all browsers.Of course, panels should be proportionally spaced by percent, but surely not any controls with text in them.
rep_movsd
Not detecting system DPI is a application issue, any GUI toolkit ( which in my opinion includes rendered HTML layouts ) should take this into account. Using font size as a measure is a silly solution, I dont want all my GUIs blown up just because I increase default font size by a point or two....
rep_movsd