關於匯入外部樣式表的目錄問題
阿新 • • 發佈:2019-02-13
在html中插入css樣式或者是js檔案的方式往往分為內部插入和外部匯入兩種途徑,今天已css樣式表為例,總結一下外部檔案匯入的路徑問題:
1.內聯樣式,即在html文件內部應用樣式:
方式一:行內樣式:
1 <p style="font-size:20px;color:red">這種是行內樣式</p> 樣式與結構緊密耦合,不推薦!
方式二: 內部樣式,一般插入在文件 head標籤中style內:
1 <html>
2 <head>
3 <title>內部樣式表演示</title>
4 <style type="text/css">
5 div{
6 width:100px;
7 height:100px;
8 backgrond:#ffccaa;
9 }
10 ul{
11 color:red;
12 font-size:12px;
13 }
14 </style>
15 </head>
16 <body>
17 <div>內部樣式表</div >
18 </body>
</html>
2.外部樣式匯入:
一 匯入方式:
1 <head>
2 <title>title of article</title>
3 <link rel=stylesheet href="http://www.dhtmlet.com/rainer.css" type="text/css">
4 </head>
二,匯入路徑:
(1) 相對路徑:
文件相對路徑:”./ “當前目錄 ” ../ ” 上一級目錄 ” / ” 下一級目錄
假設你本地資料夾如下: fff > fsfa > src > index.html ;
up.html images;
javascript;
html > now.html
css >want.css
此時 在now.html中匯入want.css,目錄為:../css/want.css 語言描述為 :匯入上級目錄(src)下的css資料夾下的want.css檔案;
在index.html檔案中匯入want.css,目錄為:css/want.css 或者./css/want.css :匯入當前目錄(src)下的css資料夾下的want.css檔案;
在up.html檔案中匯入want.css,目錄為:./src/css/want.css :匯入當前目錄(fsfa)下的src中css中的want.css檔案;