Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does HTML support floating point numbers for width? 1

Status
Not open for further replies.

gmail2

Programmer
Jun 15, 2005
987
IE
Does HTML / CSS only support integers for element width's such as DIV's etc? I'm trying to make a progress bar with a DIV and I need to add 0.5px to the width each time a function is called. JavaScript is definitely reading the increment correctly but when it gets added onto the DIV it seems to get rounded to 0 instead. Anybody got any suggestions?
 
There is no such thing as half a pixel. Pixel is defined as the smallest part of the computer graphic and as such cannot be split further. You can use half a percent, half an em, half an inch or a centimeter, even half a point, but you can't take half a pixel.
 
You could try using ems to get thinner lines:
Code:
.thinborder {border:0.1em solid black;}
Of course they will grow as the user increases font size... but for normal size fonts they will be a lot thinner than the normal 1px borders you see.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
And yet, VB uses unit of "twips" of which there are about 1500 per pixel!

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
>> How do you think any screen would manage to display half a pixel?

[lol]
Good Point - two of us looked at this and never even though of that !! So HTML / CSS will support half a percent etc then. That's good enough for me. Thanks for the suggestion also Jeff
 
Tracy, all the screens I use have size defined in pixels across and downward. If I expect them to draw me half a pixel, am I not expecting my resolution to be doubled?
 
Vragabond... you probably know this already... but if you have a 110V (US/Canada) monitor, you can easily double the resolution (and effectively display half-pixels) by switching to 220V power (as we have in Europe).

Of course, this works the other way as well... although why anyone would want to halve their resolution by switching from 220V to 110V, I wouldn't know!

The manufacturers of monitors don't want you to know about this, and they make it difficult by providing power cables that vary from country to country. Before the internet, nobody knew about this! Darn corporates!!!

Cheers,
Jeff


[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Come think of it, I did not know that. Thanks Jeff. And I did live in both Europe and US.
 
I thought twip stood for [red]tw[/red]enty [red]i[/red]n a [red]p[/red]ixel.

Lee
 
Actually there are 1440 twips in 1 inch and 1 twip = 1/20 of a point.

There isn't a true correlation between twips and pixels because twips are screen independent units and pixels are totally screen dependent.


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
BabyJeffy said:
but if you have a 110V (US/Canada) monitor, you can easily double the resolution (and effectively display half-pixels) by switching to 220V power (as we have in Europe).

And with 240V you can turn 4:3 into widescreen... I knew nVidia and ATI are shafting us!

That said, my favorite measuring unit is attoparsec :X

Reply to gmail2: if you need to increment value by 0.5px, calculate and keep that value entirely in javascript. Once calculation is done, assign value to DIVs width.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Reply to gmail2: if you need to increment value by 0.5px, calculate and keep that value entirely in javascript. Once calculation is done, assign value to DIVs width
Good suggestion but unfortunately this is for a progress bar so the value needs to be assigned back to the DIV each time the function is called. But thanks for the suggestion all the same
 
Ooo... how about using percentages for the width of the progress?

You might set the outer DIV to 300px... then set another DIV inside it (set to a solid colour and with a height) and use JS to increase it's width as a percentage. You can then rely on the browser to convert, say, 23.4523% into the correct number of pixels.

Hope that makes sense!

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Yea - that's exactly what I've already decided I'm gonna have to do!! Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top