php - css 路径不起作用 (php)

标签 php css

我正在尝试用 PHP (MVC) 制作一个简单的应用程序。我进行了路由,并在 View 中创建了一个 inc 文件夹,其中存在 head.php - header.php - footer.php。 head.php 包含在 header.php 中。在 head.php 标题中有一个 $pageTitle 变量。问题是,当我在其他文件中包含 header.php 时,即使 $pageTitle 正在更改(根据新值),也不会显示 css 文件中的样式!!!

我的head.php文件是

<head>
<meta charset="utf-8">
<title><?php echo $pageTitle ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../src/css/bootstrap.min.css" rel="stylesheet">
<link href="../src/css/main.css" rel="stylesheet">
<script src="../src/js/bootstrap.min.js"></script>
</head>

我的header.php是

<!doctype html>
<html>

<?php 
define( 'ROOT_DIR', dirname(__FILE__) );

include( ROOT_DIR.'/inc/head.php' );
// include 'inc/head.php';
// include '../app/views/inc/head.php'; 
?>

我包括标题

<?php 
$pageTitle = "login-register | Twitter";

define( 'ROOT_DIR', dirname(__FILE__) );
include( ROOT_DIR.'/inc/header.php' );

// include '../app/views/inc/header.php'; 


?>

我尝试了很多不同的选项,但没有任何效果。我搜索并尝试了一切(我认为)

最佳答案

不要使用/src/css 和/src/js 的相对路径,而是尝试使用像这样的绝对路径 -

<link href="/src/css/bootstrap.min.css" rel="stylesheet">
<link href="/src/css/main.css" rel="stylesheet">
<script src="/src/js/bootstrap.min.js"></script>

关于php - css 路径不起作用 (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30121126/

相关文章:

php - 查找字符串是否为 PHP 中的 MySQL 函数

php - 使用 swiftmailer 并发送附件

php - 购物车数据库设计: adding functionality for quantities by size

javascript - 如何将表格单元格内空div的高度设置为该单元格的高度

css - 我似乎无法让我的媒体查询为响应式网站工作

php - 在查询运行时显示加载栏和消息?

html - 如何在元素聚焦时动态更改 sass 属性?

javascript - 当到达文档中的不同点时,导航栏突出显示适当的链接

javascript - 使用 jQuery 仅针对元素列表中的悬停元素

php - 检查 file_get_contents 何时完成