haco
haco

Reputation: 23

accessing a stylesheet from a php file

So im new to php, but from what I can tell normal html should work OK in a .php file. However in my .php file it does not access my stylesheet and other assets such as pictures. I use the same lines of html in my html page and it works fine:

<head>        
    <style>
    <link rel="stylesheet" type="text/css" media="screen" href="stylesheet.css">
    <meta charset="utf-8"/>
    </style>
</head>

Looking at the network tab of the developer view, I am recieving error 404s on my images which are simple tags, but the style sheet is not even showing up.

All of this works fine in my html page and not the php page. Does php not work like this? I've seen other peoples screenshots where it looks like it does. Thanks

Upvotes: 0

Views: 98

Answers (1)

Adam
Adam

Reputation: 1304

You don't need to wrap it in <style> tags:

<head>        
    <link rel="stylesheet" type="text/css" media="screen" href="stylesheet.css">
    <meta charset="utf-8"/>
</head>

Also, learn about relative and absolute paths:

Check this out: Absolute vs. relative paths

./stylesheet.css --- Same folder as file being called

stylesheet.css --- Same folder as file being called

/stylesheet.css --- Root of project (webroot)

$_SERVER['DOCUMENT_ROOT'] --- Full path of to document/web root

$_SERVER['DOCUMENT_ROOT'] . '/stylesheet.css' --- Full path to stylesheet if in document root.

Upvotes: 4

Related Questions