问题
How do you prevent material icon text from showing up when Google's JS fails to convert them to icons?
Icons are defined in markup as such:
<span class="material-icons">icon_name</span>
Example: https://archive.fo/CKqKG/scr.png (see the top row of buttons).
Material Icons Documentation: https://material.io/icons/
This is also an issue in Google search where Google will actually read and save the div's text instead of ignoring it.
Example: https://i.imgur.com/TixS06y.png
I understand that one solution is to simply switch to .PNGs (supplied by Google). I'd like to do whatever results in less (network) load on the user's system.
Thanks!
回答1:
you can use font-display: block;
, just add this CSS to your HTML head:
<style>
@font-face {
font-family: 'Material Icons';
font-display: block;
}
</style>
for more information font-display
回答2:
I've been struggling with a similar situation: my problem was not that the icons never loaded, just that they could take a while to load on slower connections and until they loaded ugly, unformatted text like sentiment_very_satisfied would be shown on the page (often many times larger than the surrounding text as well making it very obvious).
The other solutions here didn't work for me (including font-display:block
which I thought might be promising), so I came up with my own using CSS and jQuery. I'm sure you could easily adapt it to use vanilla JS.
CSS:
.material-icons{
opacity:0;
}
jQuery:
$(window).load(function() {
$('.material-icons').css('opacity','1');
});
The trick here is that, unlike the more commonly used $(document).ready()
listener, $(window).load()
waits for all elements
来源:https://stackoverflow.com/questions/41710834/how-to-prevent-material-icon-text-from-showing-up-when-googles-js-fails-to-conv