Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari mobile does not respect CSS color attribute for HTML entity ✖

Bit of a confusing one, the color attribute is respected on the desktop version of Safari but not on mobile.

I tested it on an iPhone 5 (iOS version 9.2.1).

Sample code (first span will appear black on safari mobile):

 <html>
   <head>
      <style>
         span { color: white; }
      </style>
   </head>
   <body>
      <span>&#10006;</span>
      <span>&times;</span>
      <span>×</span>
   </body>
 </html>

and JSFiddle link: https://jsfiddle.net/9t3v8846/

Adding !important didn't do anything. Any ideas what might be causing this?

like image 231
mikespitz_8 Avatar asked Mar 11 '16 11:03

mikespitz_8


1 Answers

If any poor people come across this.. the way to fix this is to add a variation selector after the entity like so:

<span>&#10006;&#xFE0E;</span>

Essentially what is going on under the covers is that the browser decides how to render the HTML entities.

Safari on iOS prefers to use Emoji-like rendering where possible so it ignores the CSS attribute. The variation selector used above specifies that we want to use text-like rendering causing Safari to now respect any color attributes applied to it.

like image 188
mikespitz_8 Avatar answered Nov 12 '22 05:11

mikespitz_8