简体   繁体   中英

When new page is created, the css is not taken into account

I am able to automatically make a new webpage with user input, but there is only one problem: the css doesn't work on this. I know how to attach a css file to a HTML file, but this time, it just doesn't work. To help you visualize this, here is the code I have so far.

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <link rel="stylesheet" type="text/css" href="/stylesheet.css">
    </head>
<body>
<--content for webpage here-->
       </body>
</html>

So, that is the relevant HTML to go with it, and the connection of the CSS to the HTML was literally copy and pasted from another page that worked. I also made sure not to use divs, but to use classes because it could've caused problems. There is also a problem, that when I try to add the header and footer file to my document using php, there is an error as follows: Warning: include(header.php) [function.include]: failed to open stream: No such file or directory in /home/content/55/10690555/html/words/tower.php on line 2 I have no idea as to why this is happening on this page but not any other ones, so any help would be greatly appreciated. By the way, the file with the errors, is the template for creating a new document using PHP if that helps at all.

If you are using php to include the CSS files, you might probably be using include(header.php) . This might not work sometimes. Use the absolute path instead.

To get the root location, include $root = realpath($_SERVER['DOCUMENT_ROOT']); at the top and append $root variable before the filename inside the include() function.

You need to properly specify the header.php file in relevance to your webpage file. So depending on your folder structure the correct line of code will vary.

ie. if this is your folder structure:

/folderone/header.php
/foldertwo/webpage.php

This is what you need to use: include('/folderone/header.php'); . If header.php is in your root folder you only need to use include('/header.php');

The point is, include('header.php') tells php to look for the file header.php on the same folder as the webpage.

It is a clear indication of file path problem. Please check the new which you are creating by script have in the same path or directory of other files. I also observe that in your css file inclusion you are using '/' this mean respect to the root of the server. So, be sure your css file is on the document root otherwise use relative url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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