I am a casual web developer so usually I am not familiar with the details and deep design of CSS styles. As most of what I do require PHP finally all my pages execute some PHP.
I am finding myself feeling more comfortable implementing the design details in PHP included classes rather than in CSS.
For example rather than CSSing a header common across a site, I just include("header.php") on each page, "header.php" containing among others a class Palette with all the style definitions and stating the style directly in the elements (I have a personal allergy to having too many files)
So far I have found no inconveniences to this approach, in fact to me is more clear and flexible implementing the design in a procedural language than in declarative (I am a C++ programmer).
I am wondering if in the future I may regret this decision, what is wrong with this approach?
---- EDIT ----
Let me show a simple example to clarify what I mean (the example is not elaborated, definitely it would be better designed in a production case)
class Palette{
var $colorBackground="#fff";
var $colorText="#000";
}
//-------------------------------------
function styleInHeader($palette){
$css=<<<THECSS
.header{
color:{$palette->colorText};
background-color:{$palette->colorBackground};
}
THECSS;
return $css;
}
// when generating the <head>
$pal=new Palette();
echo style_general($pal);
- The advantages: The definition in class Palette is unique across all the web site
- I can apply some logic to the object palette, for example varying the colors it contains under some logic or even user interaction.
- I can subclass Palette and passing instances of these subclasses would have flexibility, in fact I'd have all the advatages of proceduran/obejct oriented tech for styling.