[英]How do i get a css page included in my header page on other php pages on my site?
I have a header page which contains the HTML head and links to my css page.我有一个标题页,其中包含 HTML 标题和到我的 css 页面的链接。
header.php
<!DOCTYPE html>
<html>
<head>
<title>ManageSchool</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css" type="text/css" />
<link rel="icon" href="Assets//favicon.ico" />
</head>
<body class="<?php echo $class ?>">
<header class="header">
<img src="../Assets/Logo.png" alt="Logo"/>
</header>
<?php include "menu.php"; ?>
<hr>
when i include this in my other page the css styles don't apply.当我将其包含在我的其他页面中时,css 样式不适用。
courses.php
<?php
session_start();
$pageIdentifier = "courses";
include "Inc/header.php";
require "Config/db.php";
echo "<p>Courses you're enrolled in.</p>";
$course_query = "SELECT courses.code, courses.name, courses.description FROM studentscourses JOIN courses ON courses.id = course_id where student_id = {$_SESSION["student_id"]};";
$course_result = mysqli_query($conn, $course_query);
$course_posts = mysqli_fetch_all($course_result, MYSQLI_ASSOC);
?>
<?php foreach($course_posts as $c_post): ?>
<table>
<tr>
<th>Course Code</th>
<th>Course Name</th>
<th>Description</th>
</tr>
<tr>
<td><?php echo $c_post["code"]; ?></td>
<td><?php echo $c_post["name"]; ?></td>
<td><?php echo $c_post["description"]; ?></td>
</tr>
</table>
<?php
endforeach;
include "Inc/footer.php";
?>
How am i supposed to import my css styles to all php pages?我应该如何将我的 css 样式导入所有 php 页面?
Your HTML link is relative to the http path of the current page您的 HTML 链接相对于当前页面的 http 路径
so所以
<link rel="stylesheet" href="styles.css" type="text/css" />
when accessed at:访问时:
https://YOURURL.com/Inc/header.php https://YOURURL.com/Inc/header.php
Will look for the the css file in the directory WEB_ROOT/Inc/会在目录WEB_ROOT/Inc/中寻找css文件
However when you include that file in your courses.php the url being accessed is:但是,当您在 course.php 中包含该文件时,正在访问的 url 是:
https://YOURURL.com/courses.php https://YOURURL.com/courses.php
So if will be looking for the css file in the directory WEB_ROOT/因此,如果要在目录 WEB_ROOT/ 中查找 css 文件
I suggest you move your CSS files into its own directory on web root eg WEB_ROOT/css我建议你将你的 CSS 文件移动到它自己的 web 根目录中,例如 WEB_ROOT/css
and then change your link to然后将您的链接更改为
<link rel="stylesheet" href="css/styles.css" type="text/css" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.