I have a php file that echos HTML and was wondering if I can use CSS in that PHP to change the look of my text. Will it work? Do I have to echo the CSS command or should I put it above the <?php ?
I am a bit confused.
Use CSS in PHP file?
Moderator: General Moderators
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
As far as I know, you can either echo the css (just as you can echo html or javascript), or you could put the css code above the <?php. Since css doesn't get used until the browser gets a hold of it and the php runs before then, the browser really won't care how you get the css to it.
You may want to have the php write it out, just in case you want to get fancy with custom css styles down the road. That way (unlike, say, the wired news site) you won't have to create cross-platform/browser javascript and the page won't "jump" after loading.
Hope that helps!
You may want to have the php write it out, just in case you want to get fancy with custom css styles down the road. That way (unlike, say, the wired news site) you won't have to create cross-platform/browser javascript and the page won't "jump" after loading.
Hope that helps!
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
Hmmm...
I tried the following first just with the external stylesheet linked and then with both external and internal to see if a cascading issue would come up, but that worked fine, too.
What does the code look like for echo-ing the css? Does your css work when you write it directly into html (not with php)?
Code: Select all
<?php
echo "<link rel="stylesheet" type="text/css" href="style_main.css" />";
echo "<style type="text/css">
echo " body {background-color: #000000;}";
echo "</style>\n";
?>You can also have php write the HTML-include
or simply do it HTML itself
<link rel='stylesheet' type='text/css' href='css/main.css'>
Bear in mind though that stylesheets have nothing to do with PHP. To PHP it's merely data it hands to the server which then sends it to the client. PHP = serverside.
Code: Select all
<?php
echo "<link rel='stylesheet' type='text/css' href='css/main.css'>";
?><link rel='stylesheet' type='text/css' href='css/main.css'>
Bear in mind though that stylesheets have nothing to do with PHP. To PHP it's merely data it hands to the server which then sends it to the client. PHP = serverside.
Last edited by patrikG on Mon Jun 16, 2003 6:00 pm, edited 1 time in total.
- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
You may want to check out W3Schools CSS2 Reference just to check to see if your css has a glitch in it. Especially as you mentioned that it didn't work when you placed it before the php code. I keep it bookmarked and easy to get to anyway, as it lets you know whether IE or Netscape support each property.