<body> <div style= "width:170; border:1 dotted PaleGreen; background-color:MistyRose"> The quick brown </div> </body>
问题:
>为什么它会回到px?像素总是首选单位吗? W3C工作草案或建议中是否定义了任何规则?
>是否有规则要求UA必须回退到首选单位?
>鉴于以上示例,以下哪项是正确的行为:
> Internet Explorer:在Quirks模式下(IE6,5,4 ..)宽度和边框宽度用于回退到px.从IE7(直到现在,IE10RP)开始,如果缺少单元,它将忽略整个规则.因此这两条规则都被忽略了
> Firefox 13:在上面的示例中,宽度回退到px,但忽略了border-width.
> Chrome 19,Opera 12,Safari 5.1.2:宽度和边框宽度都回退到px.
注意:在Microsoft-Connect上,他们说:
The issue you are reporting is by design. IE10 in standards mode ignores a width or height without a unit in compliance with the CSS standards. The unit is not optional.
解决方法
>
Why would it fallback to px? Is pixel always a preferred unit? Is there any rule defined in W3C working draft or recommendation?
它只会在怪癖模式下回落到px(而且我只相信某些属性).是的,px是首选的后备单位.这可以追溯到传统的HTML宽度和高度属性,它们将像素长度视为无单位数.
>
Is there a rule which makes it mandatory for a UA to fallback to a preferred unit?
不,因此您观察到的行为不一致.但是,在标准模式下,UA需要忽略没有单位的长度值;该单元不是可选的,如您引用的Microsoft Connect中所述.
In CSS2.1,所有非零长度值必须具有单位.
>
Given the above example,which of the following is a correct behavior:
- Internet Explorer: In Quirks mode (IE6,4..) width and border-width used to fallback to px. Since IE7 (till present,IE10RP) it ignores the whole rule if unit is missing. Therefore both rules were ignored.
- Firefox 13: In the above example width fallback to px,but border-width was ignored.
- Chrome 19,Safari 5.1.2: Both width and border-width fallback to px.
同样,基于您的页面处于怪癖模式的假设,我只能说虽然规范提到了古怪的行为,但是这些古怪行为的具体细节没有在规范中定义(对于明显的和不是 – 如此明显的原因).
我猜测Microsoft改变了IE7中的怪癖模式行为以反映无单位值的标准行为,因为所有浏览器中都存在怪癖模式(IE< 6除外)并且由相同的不正确doctype或缺少doctype触发.据我所知,标准模式下的行为并没有改变.