Dynamic CSS and a fully dynamic site

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Dynamic CSS and a fully dynamic site

Post by wiseguy12851 »

With my experience with PHP in general it is somewhat slower than ASP such as being used with AJAX and generating in general but PHP is nevertheless the most powerful tool you can use to develop websites one of which it can generate anything of any type.

In reality you only need to include 1 line of code at the top of your CSS page and rename it to .php instead of .css.

Code: Select all

header("Content-Type: text/css");
then you can insert <?PHP ?> tags throughout your CSS page for more dynamic css like time based similar to my website. Similar goes for pictures. An excellent idea for photos is instead of using z-index just have php stack up the photos and merge them unless dynamically used, and use z-index for text based content.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Dynamic CSS and a fully dynamic site

Post by kaszu »

Is this supposed to be a tutorial or a question?
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Dynamic CSS and a fully dynamic site

Post by Mirge »

I assumed tutorial. Though I'd personally rather have separate stylesheets and perhaps use PHP to determine which one to use.. rather than generate CSS with php.
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Re: Dynamic CSS and a fully dynamic site

Post by wiseguy12851 »

I should have posted this to the tutorials section but I was distinctly talking about a separate style sheet. examplestyle.css is renamed to examplestyle.php with the 1 line at the very top.

Code: Select all

header("Content-Type: text/css");
and changing the references to

Code: Select all

<link ... href="examplestyle.php" ...  /> instead of <link ... href="examplestyle.css" ...  />
from there you can add PHP tags to the CSS document such as

Code: Select all

#test
{
     background-color:<?PHP echo "black" ?>
}
of course more useful stuff can be thought of like time of day etc or even this

Code: Select all

 
<?PHP $bgcolor = $_REQUEST['bgcolor'] ?>
#test
{
     background-color:<?PHP echo $bgcolor ?>
}
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Dynamic CSS and a fully dynamic site

Post by Mirge »

What benefit does this have over creating separate stylesheets & using PHP to determine which stylesheet should be used?
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Re: Dynamic CSS and a fully dynamic site

Post by wiseguy12851 »

It simplifies everything and allows for flexibility and scalability plus adding several new features that only PHP would offer like include() and require().

more specifically it allows for useful mathematical functions like calculating custom borders sizes and widths etc... that may be repetitive like curved borders.

and if your used to traditional css then there isn't exactly a set reason that you are not able to do without php css but as for me I'm able to manage very successively and easily my css styles by adjusting a few variables in one of few neatly written css / php file that can output several css styles and combinations at certain times to suit most of my site, any time I want to make a change of any scale I adjust just a few variables and it's applied.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Dynamic CSS and a fully dynamic site

Post by Mirge »

wiseguy12851 wrote:It simplifies everything and allows for flexibility and scalability plus adding several new features that only PHP would offer like include() and require().

more specifically it allows for useful mathematical functions like calculating custom borders sizes and widths etc... that may be repetitive like curved borders.

and if your used to traditional css then there isn't exactly a set reason that you are not able to do without php css but as for me I'm able to manage very successively and easily my css styles by adjusting a few variables in one of few neatly written css / php file that can output several css styles and combinations at certain times to suit most of my site, any time I want to make a change of any scale I adjust just a few variables and it's applied.
Hm ok. I am just still not seeing any benefits to embedding PHP within a CSS stylesheet. I don't understand how it would allow for greater flexibility or scalability. If anything, it would confuse and be more difficult to maintain, IMHO. Have never worked on a project with any other developers where they used PHP in stylesheets.
Post Reply