News:

Wondering if this will always be free?  See why free is better.

Main Menu

Is it safe to convert CSS to PHP?

Started by PokémonS, May 03, 2015, 04:46:31 PM

Previous topic - Next topic

PokémonS

SMF 2.0.10

Hi,

I want cat_bar with random color and it's possible through putting CSS styles in PHP.
So I am planning convert the style template, style.css to style.php.

I know how to code them all, something like this:

Code (style.php) Select
<?php
header
("Content-type: text/css");

$color1 '#fff';
$color2 '#ddd';

$array = array($color1$color2);
$randomcolor $array[array_rand($array)];
?>


cat_bar {
background-color: <?=$randomcolor?>;
}



But my question is,
Is it safe to convert it? Have anyone try it? Is there any side/negative effect? Any suggestion?

Thanks!
きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう

Bob Perry of Web Presence Consulting

Not qualified to answer your question but this is a great idea, i'm going to follow this thread fer sure, keeping up to date on what they tell you...

You'll get some good feedback from the others here on this i'd say...

Best Regards,
Bob Perry



"The world is moving so fast these days that the man who says it can't be done is generally interrupted by someone doing it." Elbert Hubbard

Biology Forums

I believe a .css file will be read as a css file, therefore php won't be read. If you want to apply a style in a php theme template, then you can. In fact, you can override whatever is inside your main style sheet by using !important.

<style>.CLASS {background-color: #'.$color.' !important;</style>

PokémonS

Quote from: Bob Perry on May 03, 2015, 04:53:44 PM
Not qualified to answer your question but this is a great idea, i'm going to follow this thread fer sure, keeping up to date on what they tell you...

You'll get some good feedback from the others here on this i'd say...

Thanks Bob!


Quote from: Shuban on May 03, 2015, 06:09:58 PM
I believe a .css file will be read as a css file, therefore php won't be read. If you want to apply a style in a php theme template, then you can. In fact, you can override whatever is inside your main style sheet by using !important.

<style>.CLASS {background-color: #'.$color.' !important;</style>

Thanks Shuban for the answer.
I have an idea. Looks like putting them in index.template.php inside <head> may also works, with !important.

Is that better and still work?
きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう

Biology Forums

Yes, must better. It's what I do when I need it.

PokémonS

きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう



margarett

I'd like to just point something here...
MOST styling isn't dynamic. I would advise you against replacing ALL your CSS with PHP.
In 2.0, index.css is ~~55kB in size. Browsers cache CSS files, which means that they aren't transferred in every page view. By changing them to .php files, they won't be cached anymore, which consumes your bandwidth as well as your users's.

So it's a good trick, indeed. But you shouldn't replace all CSS with PHP files ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: