鍍金池/ 問答/Python  HTML/ 等效的css樣式,外鏈有效,內(nèi)嵌無效(不涉及優(yōu)先級問題),求解

等效的css樣式,外鏈有效,內(nèi)嵌無效(不涉及優(yōu)先級問題),求解

引用fontello的iconfont,復(fù)制字符到html文件中。
目錄結(jié)構(gòu)如下:

clipboard.png

其中magic.css內(nèi)容如下:

@font-face {
    font-family: 'fontello';
    src: url('../asserts/font/fontello.eot?98310639');
    src: url('../asserts/font/fontello.eot?98310639#iefix') format('embedded-opentype'), url('../asserts/font/fontello.woff?98310639') format('woff'), url('../asserts/font/fontello.ttf?98310639') format('truetype'), url('../asserts/font/fontello.svg?98310639#fontello') format('svg');
    font-weight: normal;
    font-style: normal;
}

內(nèi)嵌,除了字體路徑做了相應(yīng)更改外原封不動:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        /* 內(nèi)嵌定義的字體無效 */

        @font-face {
            font-family: 'fontello';
            src: url('./asserts/font/fontello.eot?98310639');
            src: url('./asserts/font/fontello.eot?98310639#iefix') format('embedded-opentype'), url('../asserts/font/fontello.woff?98310639') format('woff'), url('../asserts/font/fontello.ttf?98310639') format('truetype'), url('../asserts/font/fontello.svg?98310639#fontello') format('svg');
            font-weight: normal;
            font-style: normal;
        }

        span {
            font: 16px/30px fontello;
        }
    </style>
    <!-- <link rel="stylesheet" href="./css/magic.css"> -->
</head>

<body>
    <div>
        <span></span>
    </div>
</body>

</html>

效果如圖,亂碼:

clipboard.png

接著外鏈:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        /* 內(nèi)嵌定義的字體無效 */

        /* @font-face {
            font-family: 'fontello';
            src: url('./asserts/font/fontello.eot?98310639');
            src: url('./asserts/font/fontello.eot?98310639#iefix') format('embedded-opentype'), url('../asserts/font/fontello.woff?98310639') format('woff'), url('../asserts/font/fontello.ttf?98310639') format('truetype'), url('../asserts/font/fontello.svg?98310639#fontello') format('svg');
            font-weight: normal;
            font-style: normal;
        } */

        span {
            font: 16px/30px fontello;
        }
    </style>
    <link rel="stylesheet" href="./css/magic.css">
</head>

<body>
    <div>
        <span></span>
    </div>
</body>

</html>

效果如下:

clipboard.png

請問為什么效果會不同呢?感覺應(yīng)該是等效的引用。

系統(tǒng):win10 專業(yè)版 版本1067
瀏覽器:

clipboard.png

回答
編輯回答
浪婳

因?yàn)閙agic.html和magic.css所在路徑不同,對font-face里src中的“..”的解釋就得到不同的路徑了,所以有了不同的效果。

2017年2月1日 18:09
編輯回答
挽青絲

路徑不同,所以效果不同。

2017年7月6日 16:37
編輯回答
疚幼

路徑改的不徹底啊,就改了開頭倆eot的,后邊的都沒動,eot我記得是給ie用的?其它瀏覽器下自然就掛咯(因?yàn)?04)。

所以下回這種調(diào)用資源的,優(yōu)先看下網(wǎng)絡(luò)面板有沒有404吧,有的話仔細(xì)看下路徑或者路由。

2018年8月15日 05:42