如何从另一个php文件访问css文件及其样式?
我希望包括或获得一个css文件使用另一个php访问。我知道这是可能的,但我不知道怎么做,下面是我的css文件:如何从另一个php文件访问css文件及其样式?,php,html,css,Php,Html,Css,我希望包括或获得一个css文件使用另一个php访问。我知道这是可能的,但我不知道怎么做,下面是我的css文件: <style type="text/css"> .titleStyle { color:black; text-align: center; font-family: Stencil Std; } </style> titleStyle
<style type="text/css">
.titleStyle
{
color:black;
text-align: center;
font-family: Stencil Std;
}
</style>
titleStyle先生
{
颜色:黑色;
文本对齐:居中;
字体系列:模具标准;
}
我计划在另一个php或html脚本中使用此文件及其样式。我听说可能需要include或require这个词,有人能帮我解决这个问题吗?谢谢 使用
include ('css/style.css');
很简单:
使用要求
:
请注意,当您/您的托管公司的计算机或服务器不支持htaccess时,这可能并不总是有效。在我看来,这不是一件明智的事情
更多信息:考虑使用单独的头文件,如header.php HEADER.PHP
<html>
<head>
<title>TITLE</title>
<link rel="stylesheet" type="text/css" href="layout.css"/>
</head>
标题
然后将其包含到您想要的文件中
<?php include 'header.php'; ?>
我认为这不是一个好主意,因为加载页面会比较慢。而且,这不起作用,因为css文件包含
标记。@CaiHaoyang,在文件中包含一个标题(称为简单的css样式表)不是一个好主意,也不会起作用。你太难接受了
<?php
require "css/style.css"; // include and require the 'style.css' file in a directory named 'css'
require "style.css"; // include and require the 'style.css' file in current directory
require "../style.css"; // include and require the 'style.css' file in parent directory
?>
AddType application/x-httpd-php .html .htm
<html>
<head>
<title>TITLE</title>
<link rel="stylesheet" type="text/css" href="layout.css"/>
</head>
<?php include 'header.php'; ?>