douyan1921 2015-11-05 18:55
浏览 166

如何正确添加CSS文件到PHP和HTML?

I have one problem. I have three files header.php

<!DOCTYPE html>
<html lang="pl">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/resources/style.css">
    <title>System stypendialny</title>
</head>
<body>

index.php

<div id="wrapper">
    <div id="logo">
        <h1>Nazwa strony</h1>
        <p>slogan</p>
    </div>
    </div>
    <div id="header">
        <div id="title_head">Lorem ipsum</div>
    </div>
    <div id="container">
        <div id="content">
            <h2>Witaj na naszej stronie</h2>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget tortor vitae purus bibendum ornare at sit amet mauris. Aenean adipiscing velit a        tellus sodales quis commodo metus congue. Cras ac erat eget urna faucibus pellentesque sit amet eget metus. Vestibulum ac hendrerit sapien. Vivamus        consectetur dui at nisi dictum tincidunt ac ut purus. Praesent id ornare velit. Morbi fringilla, justo nec tincidunt hendrerit, mi ante ornare magna,        id sodales dolor erat quis ante. Sed vel adipiscing nisl. Etiam lectus turpis, fermentum quis vehicula at, elementum vitae nibh. Duis at leo eu purus        aliquet rutrum. Phasellus posuere, ante condimentum sagittis venenatis, sem tellus venenatis arcu, ac iaculis quam lorem at urna.
            </p>
        </div>
        <div id="sidebar">
            <h2>O nas</h2>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget tortor vitae purus bibendum ornare at sit amet mauris. Aenean adipiscing velit a        tellus sodales quis commodo metus congue. Cras ac erat eget urna faucibus pellentesque sit amet eget metus.
            </p>
            <h2>Polecam</h2>
            <ul>
                <li><a href="#">Link 1</a></li>
                <li><a href="#">Link 2</a></li>
                <li><a href="#">Link 3</a></li>
                <li><a href="#">Link 4</a></li>
            </ul>
        </div>
    </div>
    <div id="footer">
        <p>&copy Wszelkie prawa zastrzeżone. <br /> Projekt: <a href="http://www.templatki.net">Darmowe Szablony Stron</a></p>
    </div>
</div>
</body>
</html>

and view.php where I include header.php to another files

<?php


class View
{

    function __construct()
    {

    }

    public function Render()
    {
        require_once 'views/Header.php';
        $file = 'views/' . $this->controller . '/' . $this->page . '.php';
        if (file_exists($file))
            require_once $file;
        else {
            $this->message = "Nie znaleziono pliku";
            require_once 'views/Error.php';
        }
        require_once 'views/Footer.php';
    }

}

The problem is that the file css doesn't include and I don't know why. Do you have any suggestions? A tried everything but didn't work.

  • 写回答

1条回答 默认 最新

  • dongya9346 2015-11-05 19:09
    关注

    The issue is likely path related but you can be certain by inspecting the page with developer tools (control + shift + i in most browsers).

    Depending on where your view.php file is living, you'll need to adjust the link to the CSS file. Right now you just have /resources/style.css but everything else is included using the preface views/filename. If you supply your directory structure we might be able to give a solid solution but this should get you going in the correct direction as well.

    UPDATE:

    It seems you need to move up one directory using ../ since the style sheet does live in the view directory. Try changing the link to:

     <link rel="stylesheet" type="text/css" href="../resources/style.css">
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题