Page 1 of 1
Dynamic CSS and a fully dynamic site
Posted: Wed Oct 07, 2009 5:35 pm
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.
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.
Re: Dynamic CSS and a fully dynamic site
Posted: Thu Oct 08, 2009 3:51 pm
by kaszu
Is this supposed to be a tutorial or a question?
Re: Dynamic CSS and a fully dynamic site
Posted: Thu Oct 08, 2009 4:15 pm
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.
Re: Dynamic CSS and a fully dynamic site
Posted: Thu Oct 08, 2009 5:05 pm
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.
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 ?>
}
Re: Dynamic CSS and a fully dynamic site
Posted: Thu Oct 08, 2009 6:18 pm
by Mirge
What benefit does this have over creating separate stylesheets & using PHP to determine which stylesheet should be used?
Re: Dynamic CSS and a fully dynamic site
Posted: Thu Oct 08, 2009 9:12 pm
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.
Re: Dynamic CSS and a fully dynamic site
Posted: Thu Oct 08, 2009 9:15 pm
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.