Dynamic CSS

Started on the old forum in January 2011 · view the original in the archive · old links redirect here

4 replies · 420 views · started 15 years ago · 1 min read

3 participants
Mysterio Lead · 630 posts #1

I am updating a CMS and I needed to use different CSS styles for different pages and times. But having much CSS's like page1.css, page2.css, midnight.css is not enough for me. So, here is a simple trick I did:

In the html page:

<link rel="stylesheet" type="text/css" href="style.css.php" />

Then in the stylesheet (style.css.php):

<?php
header("content-type: text/css");
?>

then here goes the CSS code.

You maybe will need it for causes like, when you want to change the background depending on whats stored in cookies:

body {
background-color: <?php echo $_COOKIE["bg"]; ?>;
}

Goodnight!

mysterio.al - programming is a functional art

frostymarvelous Senior · 266 posts #2

You can simply do this.

<?=$_COOKIE['bg']?>

Instead of the whole echo string. Learnt that from another persons dynamic css.

Would appreciate if someone explained it.

Why that works.

Perfection comes at a cost

I accept liberty!

Mysterio Lead · 630 posts #3

Ok boy, thats on your choise, I just wanted to write it simple for simple users, because advanced users know that code without needing me to tell it to them. And what you mean with your message? Why that (what?) works?

mysterio.al - programming is a functional art

something else Fellow · 2,296 posts #4

frostymarvelous wrote: You can simply do this.

<?=$_COOKIE['bg']?>

Instead of the whole echo string. Learnt that from another persons dynamic css.

Would appreciate if someone explained it.

Why that works.

the equal symbol is a shortcut syntax for echo and only works with short_open_tag enabled .... using this can save valuable load time

frostymarvelous Senior · 266 posts #5

Ah. Ok. Thanks. Its been a timesaver since I found it.

Perfection comes at a cost

I accept liberty!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close