What is the Fallback Behavior for Unitless CSS Attributes?
Fallback Behavior for Unitless CSS Attributes
Introduction
When a CSS attribute lacks a unit (e.g., px, em, pt, %), browsers often exhibit distinct fallback behaviors. This article examines the rationale behind these behaviors and the relevant guidelines in W3C specifications.
Fallback to px Unit
In quirks mode, some browsers, such as Internet Explorer versions 6-5, may fallback unitless width and border attributes to px. Historically, this behavior stemmed from HTML attributes that accepted unitless pixel lengths.
Preferred Fallback Unit
While px is a common fallback unit, it is not universally preferred. W3C specifications do not mandate a specific fallback unit.
Mandatory Fallback
No W3C standard explicitly requires user agents (UAs) to fallback to a preferred unit. This lack of a clear mandate contributes to the inconsistencies observed in browser behavior.
Example Behavior
In standards mode, a UA should ignore length values without units. However, in quirks mode, browsers may exhibit varying behaviors, as demonstrated in the example:
- Internet Explorer: Ignores both width and border rules due to missing units.
- Firefox: Fallbacks width to px but ignores border.
- Chrome, Opera, Safari: Fallback both width and border to px.
Microsoft Connect Response
The statement from Microsoft Connect emphasizes that the absence of units is not optional in standards mode. Therefore, IE10 and later versions ignore rules with unitless lengths.
Conclusion
The fallback behavior for unitless CSS attributes is subject to browser-specific implementations and may vary depending on the rendering mode. While standards mode dictates the rejection of unitless lengths, quirks mode introduces inconsistencies. Developers should be aware of these behaviors to ensure cross-browser compatibility.
The above is the detailed content of What is the Fallback Behavior for Unitless CSS Attributes?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
