Safari:`all: unset;` 添加了大量 css 规则
Safari: `all: unset;` adds a large number of css rules
我有一些非常简单的 HTML,可以在 Chrome 上完美运行,但在 Safari 上却不行。根据网络检查员的说法,我的跨度应该显示绿色文本。但是它显示为黑色。
如您所见,名称 "John" 显示为黑色。但是,根据网络检查员的说法,它应该是绿色的。
在修修补补后,我发现问题出在我使用 all: unset;
上。出于某种原因,当在 <span>
的父元素之一中使用 all: unset;
时,计算出的 CSS 规则来自:
box-sizing: border-box;
color: rgb(9, 112, 19);
display: inline;
font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 13px;
height: auto;
line-height: 25px;
pointer-events: auto;
width: auto;
至
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-box-direction: normal;
-webkit-cursor-visibility: auto;
-webkit-font-kerning: auto;
-webkit-font-smoothing: auto;
-webkit-hyphenate-character: auto;
-webkit-hyphenate-limit-after: auto;
-webkit-hyphenate-limit-before: auto;
-webkit-hyphenate-limit-lines: no-limit;
-webkit-hyphens: manual;
-webkit-line-align: none;
-webkit-line-box-contain: block inline replaced;
-webkit-line-grid: none;
-webkit-line-snap: none;
-webkit-locale: en-US;
-webkit-nbsp-mode: normal;
-webkit-print-color-adjust: economy;
-webkit-rtl-ordering: logical;
-webkit-text-combine: none;
-webkit-text-decoration-line: none;
-webkit-text-decorations-in-effect: none;
-webkit-text-emphasis-color: rgb(0, 0, 0);
-webkit-text-emphasis-position: over right;
-webkit-text-emphasis-style: none;
-webkit-text-fill-color: rgb(0, 0, 0);
-webkit-text-orientation: mixed;
-webkit-text-security: none;
-webkit-text-size-adjust: auto;
-webkit-text-stroke-color: rgb(0, 0, 0);
-webkit-text-stroke-width: 0px;
-webkit-user-modify: read-only;
-webkit-user-select: text;
border-collapse: separate;
box-sizing: border-box;
caption-side: top;
clip-rule: nonzero;
color: rgb(9, 112, 19);
color-interpolation: sRGB;
color-interpolation-filters: linearRGB;
color-rendering: auto;
cursor: auto;
display: inline;
empty-cells: show;
fill: rgb(0, 0, 0);
fill-opacity: 1;
fill-rule: nonzero;
font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-optical-sizing: auto;
font-size: 13px;
font-style: normal;
font-synthesis: style weight small-caps;
font-variant-numeric: normal;
font-weight: normal;
glyph-orientation-horizontal: 0deg;
glyph-orientation-vertical: auto;
hanging-punctuation: none;
height: auto;
image-rendering: auto;
kerning: 0;
letter-spacing: normal;
line-height: 25px;
list-style-image: none;
list-style-position: outside;
list-style-type: disc;
marker-end: none;
marker-mid: none;
marker-start: none;
orphans: auto;
overflow-wrap: normal;
pointer-events: auto;
resize: none;
shape-rendering: auto;
stroke: none;
stroke-dasharray: none;
stroke-dashoffset: 0px;
stroke-linecap: butt;
stroke-linejoin: miter;
stroke-miterlimit: 4;
stroke-opacity: 1;
stroke-width: 1px;
tab-size: 8;
text-align: start;
text-anchor: start;
text-decoration: none;
text-indent: 0px;
text-rendering: auto;
text-shadow: none;
text-transform: none;
visibility: visible;
white-space: normal;
widows: auto;
width: auto;
word-break: normal;
word-spacing: 0px;
word-wrap: normal;
writing-mode: horizontal-tb;
这是不希望的,因为使用 all: unset;
的目的是删除元素的所有现有 CSS 规则。原因是它覆盖在现有网站之上,因此可以从基础网站继承 CSS 规则。我使用 all: unset;
来避免基础网站 CSS 规则干扰此应用程序。
如果我只是将 -webkit-text-fill-color: #097013;
添加到我的 CSS 规则中,它将按预期工作。 但我不明白为什么添加 all: unset;
会添加这么多 CSS 规则,而它的目的是删除它们。
在研究了 'unset' 属性 对 'all' 规则的工作原理后,我的假设似乎是错误的。 According to W3:
unset
- Changes all the properties applied to the element or the element's parent to their parent value if they are inheritable or to their initial value if not
我有一些非常简单的 HTML,可以在 Chrome 上完美运行,但在 Safari 上却不行。根据网络检查员的说法,我的跨度应该显示绿色文本。但是它显示为黑色。
如您所见,名称 "John" 显示为黑色。但是,根据网络检查员的说法,它应该是绿色的。
在修修补补后,我发现问题出在我使用 all: unset;
上。出于某种原因,当在 <span>
的父元素之一中使用 all: unset;
时,计算出的 CSS 规则来自:
box-sizing: border-box;
color: rgb(9, 112, 19);
display: inline;
font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 13px;
height: auto;
line-height: 25px;
pointer-events: auto;
width: auto;
至
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-box-direction: normal;
-webkit-cursor-visibility: auto;
-webkit-font-kerning: auto;
-webkit-font-smoothing: auto;
-webkit-hyphenate-character: auto;
-webkit-hyphenate-limit-after: auto;
-webkit-hyphenate-limit-before: auto;
-webkit-hyphenate-limit-lines: no-limit;
-webkit-hyphens: manual;
-webkit-line-align: none;
-webkit-line-box-contain: block inline replaced;
-webkit-line-grid: none;
-webkit-line-snap: none;
-webkit-locale: en-US;
-webkit-nbsp-mode: normal;
-webkit-print-color-adjust: economy;
-webkit-rtl-ordering: logical;
-webkit-text-combine: none;
-webkit-text-decoration-line: none;
-webkit-text-decorations-in-effect: none;
-webkit-text-emphasis-color: rgb(0, 0, 0);
-webkit-text-emphasis-position: over right;
-webkit-text-emphasis-style: none;
-webkit-text-fill-color: rgb(0, 0, 0);
-webkit-text-orientation: mixed;
-webkit-text-security: none;
-webkit-text-size-adjust: auto;
-webkit-text-stroke-color: rgb(0, 0, 0);
-webkit-text-stroke-width: 0px;
-webkit-user-modify: read-only;
-webkit-user-select: text;
border-collapse: separate;
box-sizing: border-box;
caption-side: top;
clip-rule: nonzero;
color: rgb(9, 112, 19);
color-interpolation: sRGB;
color-interpolation-filters: linearRGB;
color-rendering: auto;
cursor: auto;
display: inline;
empty-cells: show;
fill: rgb(0, 0, 0);
fill-opacity: 1;
fill-rule: nonzero;
font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-optical-sizing: auto;
font-size: 13px;
font-style: normal;
font-synthesis: style weight small-caps;
font-variant-numeric: normal;
font-weight: normal;
glyph-orientation-horizontal: 0deg;
glyph-orientation-vertical: auto;
hanging-punctuation: none;
height: auto;
image-rendering: auto;
kerning: 0;
letter-spacing: normal;
line-height: 25px;
list-style-image: none;
list-style-position: outside;
list-style-type: disc;
marker-end: none;
marker-mid: none;
marker-start: none;
orphans: auto;
overflow-wrap: normal;
pointer-events: auto;
resize: none;
shape-rendering: auto;
stroke: none;
stroke-dasharray: none;
stroke-dashoffset: 0px;
stroke-linecap: butt;
stroke-linejoin: miter;
stroke-miterlimit: 4;
stroke-opacity: 1;
stroke-width: 1px;
tab-size: 8;
text-align: start;
text-anchor: start;
text-decoration: none;
text-indent: 0px;
text-rendering: auto;
text-shadow: none;
text-transform: none;
visibility: visible;
white-space: normal;
widows: auto;
width: auto;
word-break: normal;
word-spacing: 0px;
word-wrap: normal;
writing-mode: horizontal-tb;
这是不希望的,因为使用 all: unset;
的目的是删除元素的所有现有 CSS 规则。原因是它覆盖在现有网站之上,因此可以从基础网站继承 CSS 规则。我使用 all: unset;
来避免基础网站 CSS 规则干扰此应用程序。
如果我只是将 -webkit-text-fill-color: #097013;
添加到我的 CSS 规则中,它将按预期工作。 但我不明白为什么添加 all: unset;
会添加这么多 CSS 规则,而它的目的是删除它们。
在研究了 'unset' 属性 对 'all' 规则的工作原理后,我的假设似乎是错误的。 According to W3:
unset
- Changes all the properties applied to the element or the element's parent to their parent value if they are inheritable or to their initial value if not