Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS not working from relative path with php 'includes'

Tags:

html

css

php

folder structure

 /
 |--index.php

 +--includes
 |--header.html

 +--css
 |--style.css

I have 2 subfolders in my main project folder. One is a folder called 'includes' and the other one is called 'css'. I have my -index.php file in the main folder -header.html in my 'main/includes' folder -style.css in my 'main/css' folder

My index.php includes the header.html like this:include_once('includes/header.html'); (this Works!)

My header.html file links the css like this:<link href='../css/style.css' type='text/css' rel='stylesheet'/> (this does NOT work!)

I don't understand why the css file is not loaded.
I have tried using the base tag, although I'm not sure I'm using it right. <base href="http://localhost/main" /> (this is NOT working)

like image 1000
Eric Avatar asked Mar 17 '23 20:03

Eric


1 Answers

You should try using

<link href='css/style.css' type='text/css' rel='stylesheet'/>

As index.php and the css folder lie at the same level.

With

<link href='../css/style.css' type='text/css' rel='stylesheet'/>,

you are asking your server to look after the style.css in upper level directory of index.php which does not exist.

You can also use / because, it points do the document root of the website.

<link href="/css/style.css" type="text/css" rel="stylesheet" />
like image 138
Pupil Avatar answered Mar 26 '23 01:03

Pupil