浏览器中已经实现的属性

首先我们来看看浏览器中实现了哪些属性。我们用一段代码来看一下。

1
Object.keys(document.body.style).filter(e => !e.match(/^webkit/))

这段代码思路非常简单,就是枚举 document.body.style 上的所有属性,并且去掉 webkit 前缀的私有属性。

在我的 Chrome 中,得到了这样一组属性:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
[
"accentColor",
"additiveSymbols",
"alignContent",
"alignItems",
"alignSelf",
"alignmentBaseline",
"all",
"animation",
"animationComposition",
"animationDelay",
"animationDirection",
"animationDuration",
"animationFillMode",
"animationIterationCount",
"animationName",
"animationPlayState",
"animationTimingFunction",
"appRegion",
"appearance",
"ascentOverride",
"aspectRatio",
"backdropFilter",
"backfaceVisibility",
"background",
"backgroundAttachment",
"backgroundBlendMode",
"backgroundClip",
"backgroundColor",
"backgroundImage",
"backgroundOrigin",
"backgroundPosition",
"backgroundPositionX",
"backgroundPositionY",
"backgroundRepeat",
"backgroundRepeatX",
"backgroundRepeatY",
"backgroundSize",
"basePalette",
"baselineShift",
"baselineSource",
"blockSize",
"border",
"borderBlock",
"borderBlockColor",
"borderBlockEnd",
"borderBlockEndColor",
"borderBlockEndStyle",
"borderBlockEndWidth",
"borderBlockStart",
"borderBlockStartColor",
"borderBlockStartStyle",
"borderBlockStartWidth",
"borderBlockStyle",
"borderBlockWidth",
"borderBottom",
"borderBottomColor",
"borderBottomLeftRadius",
"borderBottomRightRadius",
"borderBottomStyle",
"borderBottomWidth",
"borderCollapse",
"borderColor",
"borderEndEndRadius",
"borderEndStartRadius",
"borderImage",
"borderImageOutset",
"borderImageRepeat",
"borderImageSlice",
"borderImageSource",
"borderImageWidth",
"borderInline",
"borderInlineColor",
"borderInlineEnd",
"borderInlineEndColor",
"borderInlineEndStyle",
"borderInlineEndWidth",
"borderInlineStart",
"borderInlineStartColor",
"borderInlineStartStyle",
"borderInlineStartWidth",
"borderInlineStyle",
"borderInlineWidth",
"borderLeft",
"borderLeftColor",
"borderLeftStyle",
"borderLeftWidth",
"borderRadius",
"borderRight",
"borderRightColor",
"borderRightStyle",
"borderRightWidth",
"borderSpacing",
"borderStartEndRadius",
"borderStartStartRadius",
"borderStyle",
"borderTop",
"borderTopColor",
"borderTopLeftRadius",
"borderTopRightRadius",
"borderTopStyle",
"borderTopWidth",
"borderWidth",
"bottom",
"boxShadow",
"boxSizing",
"breakAfter",
"breakBefore",
"breakInside",
"bufferedRendering",
"captionSide",
"caretColor",
"clear",
"clip",
"clipPath",
"clipRule",
"color",
"colorInterpolation",
"colorInterpolationFilters",
"colorRendering",
"colorScheme",
"columnCount",
"columnFill",
"columnGap",
"columnRule",
"columnRuleColor",
"columnRuleStyle",
"columnRuleWidth",
"columnSpan",
"columnWidth",
"columns",
"contain",
"containIntrinsicBlockSize",
"containIntrinsicHeight",
"containIntrinsicInlineSize",
"containIntrinsicSize",
"containIntrinsicWidth",
"container",
"containerName",
"containerType",
"content",
"contentVisibility",
"counterIncrement",
"counterReset",
"counterSet",
"cursor",
"cx",
"cy",
"d",
"descentOverride",
"direction",
"display",
"dominantBaseline",
"emptyCells",
"fallback",
"fill",
"fillOpacity",
"fillRule",
"filter",
"flex",
"flexBasis",
"flexDirection",
"flexFlow",
"flexGrow",
"flexShrink",
"flexWrap",
"float",
"floodColor",
"floodOpacity",
"font",
"fontDisplay",
"fontFamily",
"fontFeatureSettings",
"fontKerning",
"fontOpticalSizing",
"fontPalette",
"fontSize",
"fontStretch",
"fontStyle",
"fontSynthesis",
"fontSynthesisSmallCaps",
"fontSynthesisStyle",
"fontSynthesisWeight",
"fontVariant",
"fontVariantAlternates",
"fontVariantCaps",
"fontVariantEastAsian",
"fontVariantLigatures",
"fontVariantNumeric",
"fontVariationSettings",
"fontWeight",
"forcedColorAdjust",
"gap",
"grid",
"gridArea",
"gridAutoColumns",
"gridAutoFlow",
"gridAutoRows",
"gridColumn",
"gridColumnEnd",
"gridColumnGap",
"gridColumnStart",
"gridGap",
"gridRow",
"gridRowEnd",
"gridRowGap",
"gridRowStart",
"gridTemplate",
"gridTemplateAreas",
"gridTemplateColumns",
"gridTemplateRows",
"height",
"hyphenateCharacter",
"hyphenateLimitChars",
"hyphens",
"imageOrientation",
"imageRendering",
"inherits",
"initialLetter",
"initialValue",
"inlineSize",
"inset",
"insetBlock",
"insetBlockEnd",
"insetBlockStart",
"insetInline",
"insetInlineEnd",
"insetInlineStart",
"isolation",
"justifyContent",
"justifyItems",
"justifySelf",
"left",
"letterSpacing",
"lightingColor",
"lineBreak",
"lineGapOverride",
"lineHeight",
"listStyle",
"listStyleImage",
"listStylePosition",
"listStyleType",
"margin",
"marginBlock",
"marginBlockEnd",
"marginBlockStart",
"marginBottom",
"marginInline",
"marginInlineEnd",
"marginInlineStart",
"marginLeft",
"marginRight",
"marginTop",
"marker",
"markerEnd",
"markerMid",
"markerStart",
"mask",
"maskType",
"mathDepth",
"mathShift",
"mathStyle",
"maxBlockSize",
"maxHeight",
"maxInlineSize",
"maxWidth",
"minBlockSize",
"minHeight",
"minInlineSize",
"minWidth",
"mixBlendMode",
"negative",
"objectFit",
"objectPosition",
"objectViewBox",
"offset",
"offsetDistance",
"offsetPath",
"offsetRotate",
"opacity",
"order",
"orphans",
"outline",
"outlineColor",
"outlineOffset",
"outlineStyle",
"outlineWidth",
"overflow",
"overflowAnchor",
"overflowClipMargin",
"overflowWrap",
"overflowX",
"overflowY",
"overrideColors",
"overscrollBehavior",
"overscrollBehaviorBlock",
"overscrollBehaviorInline",
"overscrollBehaviorX",
"overscrollBehaviorY",
"pad",
"padding",
"paddingBlock",
"paddingBlockEnd",
"paddingBlockStart",
"paddingBottom",
"paddingInline",
"paddingInlineEnd",
"paddingInlineStart",
"paddingLeft",
"paddingRight",
"paddingTop",
"page",
"pageBreakAfter",
"pageBreakBefore",
"pageBreakInside",
"pageOrientation",
"paintOrder",
"perspective",
"perspectiveOrigin",
"placeContent",
"placeItems",
"placeSelf",
"pointerEvents",
"position",
"prefix",
"quotes",
"r",
"range",
"resize",
"right",
"rotate",
"rowGap",
"rubyPosition",
"rx",
"ry",
"scale",
"scrollBehavior",
"scrollMargin",
"scrollMarginBlock",
"scrollMarginBlockEnd",
"scrollMarginBlockStart",
"scrollMarginBottom",
"scrollMarginInline",
"scrollMarginInlineEnd",
"scrollMarginInlineStart",
"scrollMarginLeft",
"scrollMarginRight",
"scrollMarginTop",
"scrollPadding",
"scrollPaddingBlock",
"scrollPaddingBlockEnd",
"scrollPaddingBlockStart",
"scrollPaddingBottom",
"scrollPaddingInline",
"scrollPaddingInlineEnd",
"scrollPaddingInlineStart",
"scrollPaddingLeft",
"scrollPaddingRight",
"scrollPaddingTop",
"scrollSnapAlign",
"scrollSnapStop",
"scrollSnapType",
"scrollbarGutter",
"shapeImageThreshold",
"shapeMargin",
"shapeOutside",
"shapeRendering",
"size",
"sizeAdjust",
"speak",
"speakAs",
"src",
"stopColor",
"stopOpacity",
"stroke",
"strokeDasharray",
"strokeDashoffset",
"strokeLinecap",
"strokeLinejoin",
"strokeMiterlimit",
"strokeOpacity",
"strokeWidth",
"suffix",
"symbols",
"syntax",
"system",
"tabSize",
"tableLayout",
"textAlign",
"textAlignLast",
"textAnchor",
"textCombineUpright",
"textDecoration",
"textDecorationColor",
"textDecorationLine",
"textDecorationSkipInk",
"textDecorationStyle",
"textDecorationThickness",
"textEmphasis",
"textEmphasisColor",
"textEmphasisPosition",
"textEmphasisStyle",
"textIndent",
"textOrientation",
"textOverflow",
"textRendering",
"textShadow",
"textSizeAdjust",
"textTransform",
"textUnderlineOffset",
"textUnderlinePosition",
"top",
"touchAction",
"transform",
"transformBox",
"transformOrigin",
"transformStyle",
"transition",
"transitionDelay",
"transitionDuration",
"transitionProperty",
"transitionTimingFunction",
"translate",
"unicodeBidi",
"unicodeRange",
"userSelect",
"vectorEffect",
"verticalAlign",
"viewTransitionName",
"visibility",
"whiteSpace",
"widows",
"width",
"willChange",
"wordBreak",
"wordSpacing",
"wordWrap",
"writingMode",
"x",
"y",
"zIndex",
"zoom"
]

数了一下,这里有 441 个属性(随着升级会越来越多),这非常壮观了,要想了解它们可不是一件容易的事情。接下来我们试着找到它们背后对应的标准。

小实验:找出 W3C 标准中的 CSS 属性

我们知道 CSS2.1 是一份标准,但是 CSS3 分布在无数标准中,我们需要用代码把它们整理出来,这就是我们今天的小实验内容了。

为了达到我们的目的,我们需要写一个简单的爬虫,来找一找 W3C 标准中都覆盖了哪些属性。

我们这个爬虫的思路是:用 iframe 来加载所有标准的网页,然后用 JavaScript 找出它们中间定义的属性。

第一步:找到 CSS 相关的标准。

我们来到 W3C 的 TR 页面:https://www.w3.org/TR/?tag=css

我们必须从这个页面里抓取所有的标准名称和链接,打开它的代码,我们会发现它是有规律的,这个页面由一个巨大的列表构成,我们只需要根据 tag 选取需要的标准即可。

1
document.querySelectorAll("#container li[data-tag~=css] h2:not(.Retired):not(.GroupNote)")

这段代码可以找到所有 CSS 相关的标准,我们用代码把从 HTML 结构中把它们抽取出来。可以得到一个列表。

第二步:分析每个标准中的 CSS 属性

得到了这个标准的列表,下一步我们就是分析每个标准中的 CSS 属性。

我们打开第一个标准,试着找出属性定义:https://www.w3.org/TR/2019/WD-css-lists-3-20190425/

经过分析,我们会发现,属性总是在一个具有 propdef 的容器中,有属性 data-dfn-type 值为 property。

这里我不得不感慨,W3C 的标准写得真的是十分严谨,这给我们带来了很大的方便。我们用以下代码获取属性:

1
document.querySelectorAll(".propdef [data-dfn-type=property]")

对于第一个标准 CSS Lists Module Level 3 得到了这个列表:

1
2
3
4
5
6
7
8
list-style-image
list-style-type
list-style-position
list-style
marker-side
counter-reset
counter-set
counter-increment

好了,接下来,我们来用 iframe 打开这些标准,并且用我们分析好的规则,来找出里面的属性就可以了。最终成品代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

var iframe = document.createElement("iframe");

document.body.appendChild(iframe);

iframe.src = "https://www.w3.org/TR/2019/WD-css-lists-3-20190425/"

function happen(element, type){
return new Promise(resolve => {
element.addEventListener(type, resolve, {once: true})
})
}

happen(iframe, "load").then(function(){
//Array.prototype.map.call(document.querySelectorAll("#container li[data-tag~=css] h2"), e=> e.children[0].href + " |\t" + e.children[0].textContent).join("\n")
console.log(iframe.contentWindow);
})
async function start(){
var output = []
for(let standard of Array.prototype.slice.call(document.querySelectorAll("#container li[data-tag~=css] h2:not(.Retired):not(.GroupNote)"))) {
console.log(standard.children[0].href);
iframe.src = standard.children[0].href;
await happen(iframe, "load");
var properties = Array.prototype.map.call(iframe.contentWindow.document.querySelectorAll(".propdef [data-dfn-type=property]"), e => e.childNodes[0].textContent);
if(properties.length)
output.push(standard.children[0].textContent + " | " + properties.join(", "));
}
console.log(output.join("\n"))
}
start();

这样,我们就得到了每个属性属于哪个标准,我们来看看最终结果。我把它整理成了一个列表。

至此,我们已经找出了标准中讲解的所有属性。