原文链接:Incomplete List of Mistakes in the Design of CSS
基于2023/04/10版进行的翻译,翻译的不好,还有一些段落还不理解作者表达的意思,如果有什么问题请在评论区留言讨论,我会及时修正
That should be corrected if anyone invents a time machine. :P(如果有谁发明了时光机的话,那这些错误都能被纠正:P)
-
white-space: nowrapshould bewhite-space: no-wrap(white-space: nowrap应该被改为white-space: no-wrap)- and line wrapping behavior should not have been added to
white-space超出容器时的换行行为也不应该被加到white-space功能中设置)
- and line wrapping behavior should not have been added to
-
animation-iteration-countshould just have been animation-count (likecolumn-count!)(animation-iteration-count应该就改为animation-count,就像column-count这样) -
vertical-alignshould not apply to table cells. Instead the CSS3 alignment properties should exist in Level 1. (vertical-align不应该能应用到表格单元格中,CSS3对齐属性应存在于级别1中) -
vertical-align: middleshould betext-middleorx-middlebecause it's not really in the middle, and such a name would better describes what it does.(vertical-align: middle应该被改成text-middle或者x-middle,因为他其实不是真正的中间,text-middle或者x-middle更能体现他的表现) -
Percentage heights should be calculated against
fill-availablerather than being undefined in auto situations.(百分比高度应该被计算为相对于fill-available所计算出的高度,而不是被当成在在 auto 情况下的无效值) -
Table layout should be sane. (表格布局应该更合理)
-
Box-sizing should be border-box by default. (盒模型默认就应该是
border-box) -
background-sizewith one value should duplicate its value, not default the second one toauto. Dittotranslate(). (background-size在属性只写了一个值的时候,应该把该值也赋给第二个值,也就是同时当成宽和高,而不是把第二的值默认赋成auto,translate()同上) -
background-positionandborder-spacing(all 2-axis properties) should take vertical first, to match with the 4-direction properties likemargin. (background-position和border-spacing以及所有两轴的属性,也就是通过两个值定位的属性,都应该把第一个值作为垂直那条轴的数据,这样可以和4轴定位的那些属性保持一致,就像margin那样) -
Not quite a mistake, because it was a reasonable default for the 90s, but it would be more helpful since then if
background-repeatdefaulted tono-repeat. (不算是一个很明确的错误,毕竟在90年代,background-repeat默认值是repeat是合理的,不过如果从那时起把background-repeat的默认值设置成no-repeat会更好) -
The 4-value shorthands like
marginshould go counter-clockwise (so that theinline-startvalue is before theblock-endandinline-endvalues instead of after them). (像margin这样的有4个值的属性简写时应该是逆时针的,这样inline-start才可以也应该写在block-end和inline-end前面,而不是像现在这样写在后面) -
z-indexshould be calledz-orderordepthand should Just Work on all elements (like it does on flex items). (z-index应该被改为叫作z-order或者depth,并且它应该在所有元素上都生效,就像他在flex item 上一样,目前z-index只对于定位盒子,即position属性值非static的盒子生效) -
word-wrap/overflow-wrapshould not exist. Instead,overflow-wrapshould be a keyword onwhite-space, likenowrap(no-wrap). (不应该有word-wrap和overflow-wrap,而且overflow-wrap应该作为一个white-space的值存在,就像nowrap/no-wrap这样) -
The top and bottom margins of a single box should never have been allowed to collapse together automatically as this is the root of all margin-collapsing evil. (不应该发生前一个块级元素的
margin-bottom或者说margin-block-end和后一个块级元素的margin-top或者说margin-block-start外边距坍塌的情况,这是所有外边距塌陷麻烦的根源) -
Partial collapsing of margins instead of weird rules to handle
min/max-heights? (看不懂,外边距塌陷相关的) -
Tables(like other non-blocks, e.g. flex containers) should form pseudo-stacking contexts. (看不懂,table相关的) -
The
currentColorkeyword should have retained the dash,current-color, as originally specified. Likewise all other color multi-word keyword names. (currentColor写法应该被改成current-color,就像最初定义的那样, 同样的,其他包含多个单词的的颜色关键词也应该改为连字符写法) -
There should have been a predictable color naming system (like CNS) instead of the arbitrary X11 names which were eventually adopted. (应该有一个可预测的颜色命名系统(如CNS),而不是最终采用的任意X11名称,应该是颜色关键词没有规律)
-
border-radiusshould have beencorner-radius. (border-radius应该被命名为corner-radius) -
Absolutely-positioned replaced elements should stretch when opposite offset properties (e.g. left+right) are set, instead of being start-aligned. (元素被绝对定位时的行为应该是将元素拉伸到对应的位置,而不是只是作为元素的起始坐标,就比如如果在元素上设置了绝对定位和left+right,那么该元素应该被拉伸为距离左右有left和right宽度的样子)
-
The hyphens property should be called hyphenate. (It's called hyphens because the XSL:FO people objected to hyphenate.) (属性hyphens 应该被叫做hyphenate,它之所以现在是hyphens 是因为XSL:FO的人反对叫 hyphenate )
-
rgba() and hsla() should not exist, rgb() and hsl() should have gotten an optional fourth parameter instead (and the alpha value should have used the same format as R, G, and B or S and L). (不应该有 rgba() 和 hsla() ,而是 rgb() and hsl() 提供一个可选的第四的参数,并且alpha值应该使用和RGB/BSL一样的格式)
-
Descendant combinator should have been
»and indirect sibling combinator should have been++, so there's some logical relationships among the selectors' ascii art (后代选择器应该使用»,兄弟选择器应该使用++, 这样使得选择器使用的这些字符逻辑上更合理) -
The
-blend-modeproperties should've just been-blend(包含-blend-mode的属性应该改为-blend就可以) -
The syntax of unicode ranges should have consistent with the rest of CSS, like
u0001-u00c8. (看不懂, unicode相关的) -
Unicode ranges should not have had a separate microsyntax with their own tokenization or token handling. The tokenization hacks required either to make selectors (e.g., u+a) handle things that are unicode-range tokens, or make unicode-range handle the other huge range of tokens (numbers and dimensions with and without scientific notation, identifiers, +) are both horrible. (看不懂, unicode相关的)
-
font-familyshould have required the font name to be quoted (like all other values that come from “outside” CSS). The rules for handling unquoted font names make parsingfontstupid, as it requires afont-sizevalue for disambiguation. (font-family应该接受一个被引号括起来的字体名, 就像其他使用外界资源的css属性那样,像现在这样使用没有用引号括起来的方式使得解析字体的过程很蠢,当其中包含一个font-size并且要消除歧异的时候) -
Flexbox should have been less crazy about
flex-basisvswidth/height. Perhaps: ifwidth/heightisauto, useflex-basis; otherwise, stick withwidth/heightas an inflexible size. (This also makes min/max width/height behavior fall out of the generic definition.) (Flexbox在处理flex-basis加上width/height的元素的时候应该简单点,就比如,如果width/height的值是auto时,采用flex-basis的值,否则,就以width/height的值作为不可伸缩的值, 这也使得最小/最大宽度/高度行为脱离了通用定义) -
~~:emptyshould have been:void, and:emptyshould select items that contain only white space~~ FIXED in the spec, waiting for implementations to check for Web-compat… (规范中已修复,正在等待实现检查Web兼容性, 所以删除的部分我没翻译~) -
table-layout: fixed; width: autoshould result in a fill-available table with fixed-layout columns. -
text-orientationshould have haduprightas the initial value (given the latest changes to 'writing-mode'). (text-orientation应该使用upright作为初始值, 考虑到writing-mode的最新变化) -
The
@importrule is required to (a) always hit the network unless you specify cache headers, and (b) construct fresh CSSStyleSheet objects for every import, even if they're identical. It should have had more aggressive URLbased deduping and allowed sharing of stylesheet objects. (除非使用指定缓存头,否则@import总是会发起网络请求,及时是相同的请求,应该使用更积极的基于URLbased的机制去减少重复请求,允许共享样式文件) -
Selectors have terrible future-proofing. We should have split on top-level commas, and only ignored unknown/invalid segments, not the entire thing. (选择器的向前兼容做的不好,我们应该在顶级语法上进行拆分,并且只忽略掉未知和非法的部分,而不是忽略掉整个)
-
:linkshould have had the:any-linksemantics all along. (:link应该有:any-link的语义) -
The
flexshorthand (andflex-shrinkandflex-growlonghands) should acceptfrunits instead of bare numbers to represent flex fractions. (简写的flex以及flex-shrink和flex-grow应该使用带有fr单位的参数而不是单纯的数字参数) -
The
displayproperty should be calleddisplay-type. (属性display应该被改为display-type) -
The
list-styleproperties should be calledmarker-style, andlist-itemrenamed tomarked-blockor something. (list-style应该被叫做marker-style,list-item应该被叫做marked-block或者别的什么) -
The
text-overflowproperty should always apply, not be dependent onoverflow(text-overflow应该直接生效,而不是还需要依赖于 overflow) -
line-height: <percentage>should compute to the equivalentline-height: <number>, so that it effectively inherits as a percentage not a length -
::placeholdershould be::placeholder-textand:placeholder-shownshould be:placeholder(::placeholder应该改成::placeholder-text,:placeholder-shown应该改成:placeholder) -
overflow: scrollshould introduce a stacking context (overflow: scroll应该加入一个层叠上下文) -
sizeshould have been a shorthand forwidthandheightinstead of an@pageproperty with a different definition (size应该作为设置width和height的简写形式,而不是现在作为一个和@page相关的,有完全不同含义的属性) -
We probably should have avoided mixing keywords (
span) with idents in the grid properties, possibly by using functional notation (likespan(2)). (不应该混淆关键词span,特别是在grid properties中,也许使用方法形式的span(2)会很好) -
Comments shouldn't have been allowed basically everywhere in CSS (compare to HTML, which basically only allows them where content goes), because it makes them basically unrepresentable in the object model, which in turn makes building editing directly on top of the object model impossible (注释不应该允许被写在css中的任意地方,HTML语法只允许他们出现在内容的位置,因为它使得它们在对象模型中基本上不可表示,这反过来使得直接在对象模型之上进行构建编辑不可能,还没不能理解什么意思 )
-
The alignment properties in Flexbox should have been writing-mode relative, not flex-flow relative, and thus could have reasonably understandable names like
align-inline-*andalign-block-*. (alignment属性在flex布局中应该根据writing-mode,而不是根据flex-flow,所以按理来说也应该存在像align-inline-*和align-block-*的属性) -
shape-outsideshould have hadwrap-in the name somehow, as people assume the shape should also clip the content as inclip-path. (shape-outside应该在名字上加上wrap-,因为人们认为形状也应该像剪辑路径一样剪辑内容) -
It shouldn't be
!important— that reads to engineers as “not important”. We should have picked another way to write this. (不应该有!important这种写法, 对于开发者来说 ,就好像意思是 ”不重要“ 一样,需要换一种方式写这个东西)