Reputation: 41
I'm a beginner at coding and this is probably really easy but I've been googling for 2 hours trying to figure out how to solve this problem and can't seem to.
I'm currently trying to rebuild a mess of a website as practice and making a template by using php includes: like a header, sidebar and footer file. I have extracted all the header information from one of the HTML files. I've created an index.php file in that works perfectly.
Problem is, when I use this php 'template' on another page in a different folder, it stops working. I realised it's because the css stylesheets in the header.php are linked relatively - I've tried making them absolute but it doesn't seem to work.
Right now, in my header.php file, the css is linked like this:
<link rel="stylesheet" type="text/css" href="./assets/sf.css"/>
After googling for a while, it seemed like my problem might be solved if I removed the . and simply had
<link rel="stylesheet" type="text/css" href="/assets/sf.css"/>
But that doesn't work and after trying a few different things, I've yet to find a solution and feel quite stuck.
Upvotes: 0
Views: 225
Reputation: 41
I figured it out! Just googled a little more and finally discovered a solution.
Just had to add one line of code above:
<base href="http://localhost/MAIN-FOLDER-NAME" />
<link rel="stylesheet" type="text/css" href="assets/sf.css"/>
And it appears to work everywhere now.
Upvotes: 4