CSS 不该如此复杂_html/css_WEB-ITnose
Web 前端最复杂的部分莫过于 CSS 了,细枝末节就算是规范自己也很难解释清楚。有一点我非常难以理解,规范为什么要浪费那么大精力去解释每一个 CSS 属性混用会产生的结果呢?如果每次添加一个新特性都要把先前的所有特性都考虑以便,那岂不是只会越来越笨拙?
我觉得,CSS 应该更强制化。比如给 table-cell 设置 float 甚至 position: absolute 这样的奇葩行为,该报错的直接报错,不要再去想应该怎么计算。因为没有什么场景是必须使用这样的黑魔法解决的,如果真有这样的场景那只能说 CSS 本身还不够强大。而且,就算规范中定义了这些细节,又有多少人能真正记住呢?
CSS 2.1 本身就已经是很大的一坨东西了,然后 CSS 3 又加入了一大坨特性,这些特性互相作用的结果就是让规范成倍地变厚。就像一部法律,如果它过于复杂,那么能够驾驭的人就越来越少,实用性越来越低。然而法律复杂还是情有可原的,因为具体的细节无法逃避,但是一个编码规范如此复杂有什么用?
该出现 UB 的地方就尽管顺其自然吧?即使强行去定义这些不合理的行为,并加入规范中,开发者可能也不敢去依赖这种特性。这样的东西应该称为「边缘行为(EB:Edge Behavior)」,同 UB 一样是不可靠的,说不定下一个版本的规范又会做调整呢?
很多人觉得,是历史包袱导致了改革无法顺利进行?其实看看 ES 规范,strict mode 就是一个非常好用的甩锅神器。增加一个严格模式,并且禁用掉很多历史遗留的特性,这样就可以名正言顺地引入新特性且不用考虑旧版兼容了。
说到严格模式,其实 XHTML 曾经也有严格模式,但后来的 HTML 5 太火,后来就没人再鸟 XHTML 了。总之我的观点就是,像 HTML、CSS 这样通用的东西,规范不该把精力浪费在没卵用的 EB 制定上,任其 UB 也完全没问题。

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

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.
