Why css "all: unset" works weirdly in Safari browser for MacOS?
Asked Answered
H

1

6

So basically I made this situation, the parent has the css all: unset.

Then I notice when I use Safari(Version 12.1.1 (14607.2.6.1.1)) all the children of it color only can be effected by * block, not even inline or !important.

But only color behaves that way, as you can see the background-color is using it's own property.

But it works fine in Chrome, is it a glitch in safari or I did something wrong? And how can I fix it in Safari?

* {
  color: red;                   /* Text color is using this one */
  background-color: pink;
}

.Parent {
  all: unset;
}

.Child {
  color: blue;
  background-color: yellow;     /* Background color is using this one */
}
<div class="Parent">
  <div class="Child">Some Text</div>
</div>
  • Expected result(Chrome) enter image description here

  • Wrong result(Safari Version 12.1.1 (14607.2.6.1.1)) enter image description here

Harumscarum answered 22/5, 2019 at 3:4 Comment(1)
Same thing happened to me but for text-decoration. Only occurred on iOS 15 or lower. Probably also caused by the same bug as bugs.webkit.org/show_bug.cgi?id=158782 It was fixed by using -webkit-text-decoration - so I guess probably this bug will happen any time you're using "all: unset;" and then setting a property that has a webkit equivalent. And can be fixed by specifically adding the webkit versions of things as well.Pitching
P
6

Safari uses the special property -webkit-text-fill-color. If you use that, the color works:

* {
  color: red;                   /* Text color is using this one */
  background-color: pink;
  -webkit-text-fill-color: red;
}

.Parent {
  all: unset;
}

.Child {
  color: blue;
  background-color: yellow;     /* Background color is using this one */
  -webkit-text-fill-color: blue;
}
<div class="Parent">
  <div class="Child">Some Text</div>
</div>

@ Dan Fabulich commented the bug for this below:
https://bugs.webkit.org/show_bug.cgi?id=158782

Pleuron answered 24/5, 2019 at 11:19 Comment(6)
Wow I didn’t know there’s a property for that and I thought color is for coloring texts, thanks a lot!Harumscarum
But it still makes no sense that the color property is not working :/Harumscarum
No problem! color is usually used for coloring texts, but Safari is one of the few browsers that also has -webkit-text-fill-color to override it. It causes a lot of issues unless you know about it.Pleuron
This is a filed bug on Safari. bugs.webkit.org/show_bug.cgi?id=158782Instil
@DanFabulich Thanks. I added it to the answerPleuron
They fixed the bug in Safari Technology Preview 105. webkit.org/blog/10428/… It will presumably be fixed in Safari 13.2 and higher.Instil

© 2022 - 2024 — McMap. All rights reserved.