Forum Moderators: coopster
I want to use PHP to change a CSS class. For example, I'd like to change this:
<div class="main">
to this:
<div class="notmain">
I want to accomplish this by embedding PHP in my CSS file [webmasterworld.com]. Here's the motivation:
I'm using some .cgi scripts that print HTML. Some CSS classes are hard-coded into the scripts. But, the CSS classes aren't what I need them to be. So I want to use PHP in my CSS file to change the classes.
Can PHP do this, and if so, how can I implement it?
Thanks,
Matthew
So to be able to switch between classes you will need something to test for.
- script name
- located in a certain directory
- the existence of a variable
- a variable with a certain setting
etc..
then you can do something like
if ($testvar == "cgi-files") {
// put some css here
} else {
// put other css here
}
and you will have to make the .css extension parsed by php as mentioned in the thread you referenced.
You can have php decide which class to use or you can have php define how to define the class and always use the same class. The latter method is detailed in the post you cite. The former could be done like so.
if ($x) {
$css_class = "main";
} else {
$css_class = "notmain";
}
echo "<div class=\"$css_class\">";
Tom
I meant that Matt was talking about two different things.
1. He wants to change the class name in the div and change the CSS that way (i.e. use a different class altogether)
2. He wants to change his CSS (i.e. change the class definition).
The referenced thread and JK answered how to do #1, I was addressing #2.
I thought about amending my post after seeing JK's, but didn't. Sorry for the confusion.
Tom