2016-09-16 4 views
0

は、ここでこれはビューであるエクスプレスJS部分ロードしないスタイルシート

<link href="https://fonts.googleapis.com/css?family=Dosis" rel="stylesheet"> 
<link href="../../public/stylesheets/styles.css" rel="stylesheet" type="text/css"> 

、私は私の部分のいずれかのファイル(head.ejs)に持っているものです。 'public'フォルダは2つ上のディレクトリです。

私のapp.jsファイルには何も特別なものはありません。ちょうど基本的なルーティングのもの。

私のアプリを実行するたびに、styles.cssは適用されません。私はそれをChrome開発ツールのソースの1つとして見ることができますが、そこには空白のようです。ここで

ここStyles.cssをファイル

body { 
    font-family: 'Dosis', sans-serif; 
    font-size: 5em; 
    color: red; 
} 

はhome.ejsは、サーバから提供するときは、../../を与えることができない

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

    <head> 
     <% include ./partials/head %> 

     <title><%= title %></title> 
    </head> 

    <body class="container"> 

     <main> 
      <div class="jumbotron"> 
       <h1>Hello!</h1> 
       <p>Welcome!</p> 
      </div> 
     </main> 


     <% include ./partials/scripts %> 
    </body> 


</html> 

答えて

1

ファイルです。

代わりに、あなたの急行に

app.use(express.static(path_to_public_folder));

を追加および変更あなたのhead.ejs

<link href="https://fonts.googleapis.com/css?family=Dosis" rel="stylesheet"> 
<link href="/stylesheets/styles.css" rel="stylesheet" type="text/css"> 
関連する問題