繁体   English   中英

如何在我网站上的其他 php 页面上的标题页面中包含一个 css 页面?

[英]How do i get a css page included in my header page on other php pages on my site?

我有一个标题页,其中包含 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>

当我将其包含在我的其他页面中时,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"; 
?>

我应该如何将我的 css 样式导入所有 php 页面?

您的 HTML 链接相对于当前页面的 http 路径

所以

<link rel="stylesheet" href="styles.css" type="text/css" />

访问时:

https://YOURURL.com/Inc/header.php

会在目录WEB_ROOT/Inc/中寻找css文件

但是,当您在 course.php 中包含该文件时,正在访问的 url 是:

https://YOURURL.com/courses.php

因此,如果要在目录 WEB_ROOT/ 中查找 css 文件

我建议你将你的 CSS 文件移动到它自己的 web 根目录中,例如 WEB_ROOT/css

然后将您的链接更改为

<link rel="stylesheet" href="css/styles.css" type="text/css" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM