When a new page is created, css is not counted

I can automatically create a new web page with user input, but there is only one problem: css is not working on this. I know how to attach a css file to an HTML file, but this time it just doesn't work. To help you visualize this, here is the code I have.

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, this is the corresponding HTML code, and the CSS / HTML connection was literally copied and pasted from another page that worked. I also tried not to use divs, but to use classes because it could cause problems. There is also a problem that when I try to add a header and footer file to my document using php, an error occurs: 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 why this is happening on this page, but not any others, so any help would be greatly appreciated. By the way, the error file is a template for creating a new document using PHP, if that helps at all.

+4
source share
3 answers

If you use php to include CSS files, perhaps you are using include(header.php) . Sometimes this may not work. Use the absolute path instead.

To get the root location, enable $root = realpath($_SERVER['DOCUMENT_ROOT']); above and add the $root variable in front of the file name inside the include() function.

+3
source

You need to correctly specify the header.php file depending on your web page file. Therefore, depending on the structure of your folder, the correct line of code will change.

i.e. 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 need to use include('/header.php');

The point, include('header.php') tells php to look for the header.php file in the same folder as the web page.

+1
source

This is an explicit indication of the problem with the file path. Verify that the new one you create with the script has the same path or directory of other files. I also notice that in your css file inclusion you use '/', this is the average value for the server root. So, make sure your css file is in the root directory of the document, otherwise use a relative url.

0
source

Source: https://habr.com/ru/post/1485543/


All Articles