2015-12-15 118 views
0
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="UTF-8"/> 
     <link rel="css" type="text/css" href="stylesheet.css"/> 
    </head> 
    <body> 
     <p> 
      <strong>C</strong>ascading 
      <strong>S</strong>tyle 
      <strong>S</strong>heets 
     </p> 
    </body> 
</html> 


p { 
    color: blue; 
    text-decoration: underline; 
    } 
strong { 
    color:red; 
    } 
body { 
    background: aqua; 
    } 

由于某种原因,这不会加载。我通过CSS和HTML验证器运行它,但是我使用开发人员工具,并且它没有显示附加的CSS样式表,并且我的(非常基本的)格式化没有被应用。我看了一些其他问题,没有解决这个问题。外部CSS样式表无法加载

回答

5

尝试rel="stylesheet",而不是rel="css"

<link rel="stylesheet" type="text/css" href="stylesheet.css"/> 

如果你的文件路径是正确的,那么它必须加载CSS,就这么简单

3

让我,如果它的工作原理

HTML DOC

<!DOCTYPE html> 
    <html lang="en"> 
     <head> 
      <meta charset="UTF-8"/> 
      //Change rel to stylesheet and it done 
      <link rel="stylesheet" type="text/css" href="stylesheet.css"/> 
     </head> 
     <body> 
      <p> 
       <strong>C</strong>ascading 
       <strong>S</strong>tyle 
       <strong>S</strong>heets 
      </p> 
     </body> 
    </html> 

stylesheet.css中

p { 
     color: blue; 
     text-decoration: underline; 
     } 
    strong { 
     color:red; 
     } 
    body { 
     background: aqua; 
     } 
2

读到这里有一个例子:

<link rel="stylesheet" type="text/css" href="mystyle.css"> 

要加载外部CSS,你必须包括链接标签

Check live demo

里面的CSS文件的引用