简体   繁体   English

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

[英]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.

相关问题 如何阻止用户使用PHP或mod重写查看我的网站上没有索引页但其他页面的文件夹? - How can I stop users from viewing folders that have no index page but other pages on my web site using PHP or mod rewrite? 如何从我网站的某些特定页面中隐藏包含在 header 页面中的页面? - How to hide an included in header page from some specific pages in my website? 我的网站有一个php标头,其中包含css动画,但我不想在某些页面上出现动画 - I have a php header for my site, with a css animation in it, but I don't want to animation to occur on certain pages 如何获得Apache显示我的PHP页面? - How do I get Apache to display my PHP page? 如何使用 Drupal 在另一个页面中调用我的 CSS 或 JavaScript 文件并将它们包含在多个页面中 - How do I use Drupal to call my CSS or JavaScript files in another page and include them in multiple pages 如何一次将一个PHP变量从一个页面转换为另外两个页面? - How do I get a PHP variable from one page to 2 other pages at once? 我怎样才能让我的网站的访问者访问我的网页,无需添加页面扩展 - How can I make my site’s visitors access my web pages without adding the page extension 我的页面内容显示在我的 header 上面。如何将它移到我的 header 下面? - My page content is displayed over my header. How do I move it below my header? 除了header()以外,还有什么方法可以通过PHP重定向到我网站上的其他页面? - Any way to redirect to another page on my site with PHP, besides header()? 如何在wordpress网站上获取博客页面,以在帖子编辑器中显示文本和图像,使它们看起来相同? - How do I get the blog page on my wordpress site to show the text and images in the post editor to look the same?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM