T. Hinton T. Hinton - 5 months ago 6x
HTML Question

Including external stylesheets in a PHP file

<link href="/app/app.css" rel="stylesheet" type="text/css">

The above is the code I'm using to access a stylesheet, but it's not working at the .

Some extra details:
This is in a
file, but it's located within the head of an
I'm working on a temporary url (i.e. 'my.ipa.dd.res/mydomain.com/dir/'). This might be the reason it's not working.

It's a stylesheet I'd like to use on several pages, which is why I'm trying to point to a root directory (so that I don't need the file in every single folder I create).


If you remove the leading slash it will look for the css file in the folder relative to the current.

<link href="app/app.css" rel="stylesheet" type="text/css">

Edit: to reuse in multiple scripts in different dirs you would need to specify an absolute path, so to avoid having to change it in multiple places when you go live (ie stop using the temporary url) you should define a variable.

// set absolute path to the stylesheet
$cssPath = 'http://my.ipa.dd.res/mydomain.com/dir/';


<link href="<?php echo $cssPath; ?>app/app.css" rel="stylesheet" type="text/css">

Depending on your php architecture you may need to define $cssPath as a global or you may be able to add it to an existing config variable. This is completely dependent on your framework.