Possible Duplicate:
Evenly distributed height of child elements with CSS
Lets say i have a design with 6 DIVs that are float left with a width of 16.666%. So the document size is splited in 6 parts.
Now if i have a document size of lets say 620px wide this would make each part 103.333px. Since i don't know screens that can show partial pixels :) I wonder how the browser handles the partial pixels.
Here is my testcase: http://jsfiddle.net/dhQh2/ (Just resize the window to get a result)
When resizing it seams that the 6 DIVs keep the same size. But it some cases it can't be. How does the browser handle those partial PX values?
The CSS Pixel Device-Width can be calculated by dividing the Pixel Width by the CSS Pixel Ratio, and rounding it to the nearest integer.
The term CSS pixel is synonymous with the CSS unit of absolute length px — which is normatively defined as being exactly 1/96th of 1 inch.
If, for example, you're using a %
width, and the exact width should be 103.333px
, then the browser must make a decision on how display that.
Different browsers make different decisions, read these links for more information:
I particularly like this explanation from John Resig/David Baron of why this is even a problem:
I was talking this over with some Mozilla developers and David Baron explained the situation quite well:
We’re trying to meet a bunch of constraints that can’t all be satisfied at the same time (the proof is left as an exercise to the reader, though I may have actually written it out once in a Bugzilla comment):
4 adjacent objects of width/height 25% (for example) starting at one edge of a container should end exactly at the other edge; there should never be an extra pixel in the container and they should never be wrapped due to being a pixel to wide
objects that are logically adjacent should always touch visually; there should never be a pixel gap or a pixel of overlap due to rounding error
objects given the same width should occupy the same number of pixels
object boundaries should always (visually) be aliased to a specific pixel boundary in the display (they should never be blurred)
The one [Mozilla] sacrifices is typically (3), except for borders where we sacrifice (1) by rounding the widths to pixel boundaries much earlier.
See this question for a JavaScript fix that forces consistency:
Evenly distributed height of child elements with CSS
Another relevant question:
Are the decimal places in a CSS width respected?
They go in the heaven of pixels ;)
Just joking. Most likely different browsers deal with it in different ways.
The first approach coming in my mind, is to calculate the width of each area. Then round it to the nearest int. The rest of the pixels gets just left empty.
Another approach, could be filling the last area, whatever it is the width (with a small margin of errors).
Very interesting question: it could be nice to have the control over this behaviour with css indeed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With