Flag Emojis not rendering

后端 未结 3 500
一生所求
一生所求 2021-02-05 01:51

I have a dropdown menu on my header that I use to display phone numbers for different countries and I need to put a flag on its side, but no flags are showing, only the letter r

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 02:12

    The flag emojis may not render regardless of what you do, depending on the platform (rather than merely the browser and/or the browser font). To find out, go to https://emojipedia.org/search/?q=emoji+flags and look at the rendering of the emoji flag for Djibouti, to the left of the text "Flag: Djibouti".

    If you see an image of a flag all is well but if you only see DJ then the emoji flags may not be supported. I visited that page on an iPad, Linux Mint 18.2 and Windows 10, and this is what I found:

    • The Djibouti flag emoji rendered on the iPad.
    • The Djibouti flag was rendered as DJ on Linux Mint 18.2 using Firefox.
    • The Djibouti flag was rendered as DJ on Windows 10 using Firefox, although this was expected since "Microsoft doesn't support any country flags on Windows, instead showing the two-letter country codes".

    So if you only want to render emoji flags in the browser on Apple platforms you should be fine, and if you want to render emoji flags in the browser on Windows it will render the two character country code instead. I'm not sure about the situation on Linux since although it didn't work for me in my environment, I couldn't find anything explicitly stating that it should or should not work.

    An alternative to using Unicode emoji flags if you need this working on all platforms is to download free emojis which are actually just small png images. Here are some samples for the Argentinian flag.


    Update:

    In the absence of a true solution as explained above, here's an alternative approach which does not use Unicode emojis, but instead uses downloaded .png images:

    
    
        
            Flag demo
            
            
            
            
        
        
            

    Flag demo

    The content of the .css file (flagdemo.css) is identical to that provided by Alvaro Montoro in this SO answer to the question How to add images in select list?.

    Since this approach only uses standard HTML and CCS (no Javascript or JQuery) it should work on any platform:

提交回复
热议问题