2017-02-17 31 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>标签内,就像前面的示例中一样。

相关问题