/    Sign up×
Community /Pin to ProfileBookmark

PHP + CSS issue

How would I put a php variable in a css file for the path of an image? like this? As it doesnt seem to work. Any ideas?

body {
font:0.75em/1.5 “Trebuchet MS”, Arial, Verdana, helvetica, sans-serif;
background: #E1E6E2 url(<?php echo $path ?>/images/bg_body.gif) repeat-y top center;
}

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 17.2005 — could you show what you have before this code as I have no idea where you're defining $path...
Copy linkTweet thisAlerts:
@ShrineDesignsDec 17.2005 — save the css file to a php file instead and add this to the top of the document&lt;?php
header("Content-Type; text/css");
?&gt;
of course an easier method would be to use a "root" relative or absolute path, thus, no need for php
Copy linkTweet thisAlerts:
@bokehDec 17.2005 — of course an easier method would be to use a "root" relative or absolute path, thus, no need for php[/QUOTE]I second that. Use a full http path that you can call up directly from the location bar of a browser. Example:[code=html]http://example.com/stylesheets/mystyles.css[/code]

[B]Point two:[/B] and no one has mentioned this so far... if you use a relative path in a stylesheet that path is relative to the stylesheet and not the html document.
Copy linkTweet thisAlerts:
@solidaritiauthorDec 17.2005 — Firstly I had a php include 'config.php'; statement in there config.php is where I created the $path variable but then I took that out as it is a bit stupid. Cos it wouldnt work in a css sheet, would it.
Copy linkTweet thisAlerts:
@solidaritiauthorDec 17.2005 — I've tried this, but for some reason it doesnt work? There are no errors it just doesnt use the stylesheet.

save the css file to a php file instead and add this to the top of the document&lt;?php
header("Content-Type; text/css");
?&gt;
of course an easier method would be to use a "root" relative or absolute path, thus, no need for php[/QUOTE]


Do I have to change something in this line, calling the stylesheet?
[code=php]
<link rel="stylesheet" href="<?=$path?>/assets/css/default.php" media="screen,projection" type="text/css" />[/code]
Copy linkTweet thisAlerts:
@solidaritiauthorDec 17.2005 — Scrap that last question I searched on the tinternet for an answer and came across this http://www.barelyfitz.com/projects/csscolor/ explaining it: My issue was that I didnt have the <?php ?> tags on the same line. Duhh.

Thank you every one!!!!
×

Success!

Help @solidariti spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...