问题
Here is my problem, I have 2 link rel tags in my html index header. One tag is for my stylesheet the other is a shortcut icon link rel to use a icon in my browser tab (fyi using FF19).
<link rel="shortcut icon" href="tophat2.ico"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
Each rel link works fine on its own. when I have them one after another though the one on the bottom (being parsed second) is the only one that is displayed however. They appear to be overriding eachother so I conclude I cannot have both a icon shortcut and a stylesheet each as a separate rel link but that is the only method I can find via Google so I am stuck.
回答1:
See http://mathiasbynens.be/notes/rel-shortcut-icon. It says:
Most sites use the following HTML to specify a favicon:
<link rel="shortcut icon" href="/favicon.ico">
Looks okay, right? Guess what — it isn’t!
Today, I learned that shortcut is not a valid link relation. Indeed, it doesn’t show up in section 4.12.5 of the HTML5 specification on ‘link types’. It is, in fact, proprietary to Internet Explorer. Without IE, rel="icon" would suffice to specify a favicon.
Since you are using Firefox, that would explain why it isn't working. Try just this:
<link rel="icon" href="tophat2.ico"/>
But be aware that this may not work in IE 8 or below. Later on in that same post it says:
If the shortcut value is omitted from the rel attribute, Internet Explorer ignores the declaration entirely, searches for a file called favicon.ico in the site root, and uses that instead. In fact, almost every browser does that when there’s no link rel="icon" specified. Using rel="icon shortcut" won’t work in IE either, since it doesn’t treat the rel attribute as a space-separated list.
Just make sure to always put the favicon in the root directory of your site, and name it favicon.ico
回答2:
OK I FIXED IT!!! I have no idea why the ** this worked but it did. I copied my rel link=icon tag and pasted it as a duplicate above the 2 waring rel links. The duplicate being parsed first appears broken which doesn't matter but now the 2 below work so I have a working stylesheet and icon. Thanks for trying to help everybody. This one shall probably remain a mystery.
来源:https://stackoverflow.com/questions/15193307/stylesheet-link-rel-and-shortcut-icon-link-rel-override-each-other-so-i-cannot-u