Theodore Steiner
Theodore Steiner

Reputation: 1605

PHP - Including Files Not accessing Stylec

I'm having a problem with included files accessing the style sheet in my header.php file. Screen shot of file structure

I've created a very basic outline, with just a nav element outline, to see if I could get my inclusions working properly. My index.html has two links:

For whatever reason, my test2.php, although including the header.php element, does not bring in any of the styles. Below is my code from test.php and test2.php, what exactly am I missing?

Test.php

<?php
    include 'includes/header.php';
?>

Test2.php

<?php
    include 'header.php';
?>

Style.css

nav {
    border: 1px solid;
    width: 95%;
    height: 50px;
}

Header.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="style/style.css" />
</head>
<body>
    <nav></nav>

Upvotes: 0

Views: 72

Answers (2)

Roshan
Roshan

Reputation: 842

I think you should use ../ to read it's previous containing directory.

It should be like this:

 <link rel="stylesheet" href="../style/style.css" />

OR You can set the base_url of your website, so it will be more flexible even you uploaded it on a hosting.

 <link rel="stylesheet" href="<?=base_url().'style/style.css';?>" />

You can read more about creating base_url

Hope this helps!

Upvotes: 2

Raynaldo
Raynaldo

Reputation: 21

what is the meaning of :

My index.html has two links:

one to a page at the root level, test.php
a second that is within the includes folder, test2.php.

if that means your index.php contain :

include 'test.php';
include 'includes/test2.php';

you must set your header.php stylesheet link base on your index.php position/directory, like this :

<link rel="stylesheet" href="style/style.css" />

because your index.php that called header.php through test.php and test2.php.

Upvotes: 0

Related Questions