失去的像素在一个百分比的CSS布局中去哪里?

前端之家收集整理的这篇文章主要介绍了失去的像素在一个百分比的CSS布局中去哪里?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Possible Duplicate:
07000

让我说我有一个设计,有6个DIVs,浮动左边,宽度为16.666%。
因此文档大小分为6部分。

现在如果我有一个文档大小可以说620px宽,这将使每个部分103.333px。因为我不知道可以显示部分像素的屏幕:)我想知道浏览器如何处理部分像素。

这是我的测试用例:
http://jsfiddle.net/dhQh2/(只需调整窗口大小以获得结果)

当调整大小时,6 DIV保持相同的大小。但有些情况不可能。浏览器如何处理这些部分PX值?

解决方法

例如,如果您使用的是%宽度,并且确切的宽度应为103.333px,那么浏览器必须对显示方式做出决定。

不同的浏览器做出不同的决定,阅读这些链接了解更多信息:

> http://ejohn.org/blog/sub-pixel-problems-in-css/
> http://elasticss.com/determination-of-algorithms-used-for-percentage-based-rounding-divs-on-browsers-and-css-frameworks/

我特别喜欢John Resig / David Baron的这个解释,为什么这甚至是一个问题:

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):

  1. 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

  2. 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

  3. objects given the same width should occupy the same number of pixels

  4. 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.

看到这个问题,一个强制一致的JavaScript修复:

Evenly distributed height of child elements with CSS

另一个相关问题:

Are the decimal places in a CSS width respected?

原文链接:https://www.f2er.com/css/219157.html

猜你在找的CSS相关文章