Is it possible for me to put php in a css file eg to randomize a color.
Printable View
Is it possible for me to put php in a css file eg to randomize a color.
I'm not sure but there's one way of finding out , test it by trying it out ;).
If it doesn't work by doing it in the stylesheet then if it's something like the colour for one certain thing, have the css within the HTML tags with the php controlling it ;).
If I direct css via <link> in a .css will that still allow php?
Why not make CSS files for the colours you want then randomize the css file that is included.
no make a file i.e css.php
and haveCode:<style type="text/css">
css goes here and you can use php if u use <?PHP around the bit you want phped dont forget ?> to close :)
</style>
imo?
and I already have a style.css is there any bypass, eg redirect from .css to .php or could I use mod rewrite :S
huh what ?
inside your style.css put this:
.style1{
//styles here
}
.style2{
//styles here
}
.style3{
//styles here
}
.style4{
//styles here
}
Then in your main file place a php script that randomizes to use
<div class="style1"></div>
or
<div class="style2"></div>
or
<div class="style3"></div>
or
<div class="style4"></div>
or use <span>'s, whatever you need :p
Easyest way no ?
(PS: imo = in my opinion)
The thing is I already have like 60 pages, so i was jw if it was possible to change the .css or .htaccess
Add this to the top of your .css file (you can add more colours if you want)
Then to display a random colour use this (example)PHP Code:<?php
$colour[] = "#FFCCCC";
$colour[] = "#FFFFFF";
$colour[] = "#000000";
srand ((double) microtime() * 1000000);
$colour2 = rand(0,count($colour)-1);
?>
:)PHP Code:body {background-color: <?php echo "$colour[$colour2]"; ?>;
font-size: 12px;
font-face: arial;
}
Can I use php in the .css?
Will do.
Make life easy for yourself:
style.php
And to use the above what you could do is like....PHP Code:<style type="text/css">
body{
color: <?=$_GET['color']?>;
}
</style>
You don't necessarily have to do it like that but that is just an example of how you could do it. So basically just make it a php file and then include/require it instead of using a css link.PHP Code:<?php
require('style.php?color=red');
?>
No you can't use php in a .css file. I believe you could do this by just using
<style>
CSS HERE
</style>
at the top of each php page as you would be able to put php inside that.
Do this:
style.php
Then just doPHP Code:<?php
header("Content-type: text/css");
?>
CSS HERE <?="with php aswell"; ?>
HTML Code:<link href="style.php" rel="stylesheet" type="text/css" />
Ahaha beat me to it! Grr.