2017-02-17 58 views
-3

我想知道如何使用所有css和bootstrap在PHP中加載html頁面。我已經使用了「include(file.html)」,但它只是顯示沒有任何CSS的純HTML。有沒有什麼方法可以加載鏈接在HTML文件中的CSS?謝謝如何在PHP中使用css加載html頁面

+2

將其重命名爲'.php'或指示您的服務器將這些「as」作爲php - 問題有點不清楚,但包含哪些內容以及如何運行。 –

+0

你不應該忽視評論/回答,或放棄/離開你的問題。 –

回答

0

確保您有一個<link>標記,如下所示在您的HTML。但是,直到您將HTML發送到瀏覽器時,纔會包含CSS。否則,您將不得不在HTML的標題中使用<style></style>標記(同樣,內聯樣式也是可能的)。注意:鏈接標記假定您的webroot中有一個名爲CSS的目錄。

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Title of the document</title> 
     <link type="text/css" rel="stylesheet" href="css/styles.css"> <!-- Right here.--> 
    </head> 
    <body> 
     The content of the document...... 
    </body> 
</html> 

在頭CSS可能看起來像......

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Title of the document</title> 
     <style><!-- Right here.--> 
      h1 {color:red;} 
      p {color:blue;} 
     </style> 
    </head> 
    <body> 
     The content of the document...... 
    </body> 
</html> 

如果你改變你的文件file.php的名字,你也許可以簡單地使用include/require styles.cssfile.php像這樣裏面:

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Title of the document</title> 
     <?= include 'styles.css'; ?> 
    </head> 
    <body> 
     The content of the document...... 
    </body> 
</html> 

但是,請確保您的include_path設置正確。此外,這樣做意味着將各種選擇器和規則放在<style></style>標籤內,就像前面的示例中一樣。