Jump to content

Using PHP and CSS together


fedoracore

Recommended Posts

hi. i've been using a php file for my css like so:

## the HTML:<link rel="stylesheet" href="style.css.php" mediate="screen" />## the PHP:header("content-type: text/css");?>html selectors {properties:values;}## OR the alternative where i'd use@import url('stylesheet.css');## so i get the benefit of CSS syntax highlighting

i decided i wanted to try using a _GET value to send info about certain links on a page-- and depending upon which links were selected, i would either "hide" or "un-hide" a list of links-- a little magic trick so i can have all of the content on the page at once, and simply control what is visible by using the "display: none" as is often done w/ the [more...] type thin in a blog for example-- so depending on what the value of the _GET variable is, i would modify a selector from

ul#navlist {display:none;}## to this:ul#navlist {display:block;}

which i've been doing by way of something like this:

if ((isset($_GET['val'])) && ($_GET['val'] == "something")) { print 'ul#navlist {display:block;}';}

-- but i can't seem to get it to work right. maybe it would never work that way-- but if i'm on the right track w/ it, i'd appreciate some help in how to format the code. would i use print() to do the "new" CSS output (upon the if else conditional logic), or am i better off using the @import -- and if so, should the @import be part of an if() statement itself? etc., etc., -- there are so many different possibilities-- what is the CORRECT way to do it? i realize it would be probably a TON more easy to do w/ javascript, but i thought this would be a cool thing to try. i'm totally open for suggestions here-- if it's all futile, please let me know what you think.thanks!!

Link to comment
Share on other sites

With PHP, the only way that the invisible content will be made visible is if a request was sent back to the server and a response was sent back to the browser. If this is the case, I don't see any benefit of sending the invisible content in the first place. You could use the _GET value to determine whether to send the content or not. If the value is not set, then simply don't send the content. If you want to be able to make invisible content visible without sending a request back to the server (i.e. refreshing the page), then you'll have to use client-side script (javascript).My two cents. :)

Link to comment
Share on other sites

Have u tryied just to print out like html?I mean

.example {  font-color : <?php echo $color ?>}

or some like that?I have seen dynamic css, and it is very usefull, since u can save a lot of time in coding and files to store, not just for fooling. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...