half-pixels, should they be converted to integer ?

S

Stevo

If I'm trying to position a DIV using a calculation (e.g. newpos=x/2;),
should I be converting the number to an integer?

There are of course no physical half-pixels on the screen, so if I were
to set the .style.left property of a DIV to "13.5px" then it's up to the
browser how it treats that. It might round down, round up, or do some
anti-aliasing to make it look like it's positioned at 13.5px.

What's the general recommendation for the pixel values being set to
..style.left and .style.top ?
 
S

Stevo

Stevo said:
If I'm trying to position a DIV using a calculation (e.g. newpos=x/2;),
should I be converting the number to an integer?

There are of course no physical half-pixels on the screen, so if I were
to set the .style.left property of a DIV to "13.5px" then it's up to the
browser how it treats that. It might round down, round up, or do some
anti-aliasing to make it look like it's positioned at 13.5px.

What's the general recommendation for the pixel values being set to
.style.left and .style.top ?

I should add, that I've always been converting them to integer so far.
But recently I was looking at some HTML in Firebug and saw it showing a
left property of a div as "135.5px". That made me wonder whether I
should stop converting to int and leave it up to the browser to decide
how it will deal with half pixel values.
 
T

The Natural Philosopher

Stevo said:
I should add, that I've always been converting them to integer so far.
But recently I was looking at some HTML in Firebug and saw it showing a
left property of a div as "135.5px". That made me wonder whether I
should stop converting to int and leave it up to the browser to decide
how it will deal with half pixel values.

I suspect (with zero justification), that the browser does this anyway.
 
A

Antonello Pasella

If I'm trying to position a DIV using a calculation (e.g. newpos=x/2;),
should I be converting the number to an integer?

There are of course no physical half-pixels on the screen

Yes, but there are half pixels in CSS

div {width:150.5px; float:left}

<div></div><div></div>

The two divs are together 301px wide

Bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top