Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
0
Archived

Build Your Site With Dynamic CSS

4 comments
33% Upvoted
This thread is archived
New comments cannot be posted and votes cannot be cast
level 1

Terrible idea. Leave your CSS file static, and use proper style classes in your generated HTML document to get a dynamic result. Not a single case presented in this blog post qualifies using PHP to create a CSS file like that. Also, his CSS file isn't cached, resulting in a new request every page load. That makes your site slower.

level 1
[deleted]
2 points · 8 years ago

Gah, always makes me sad when i see PHP-code like that.

$css = array(
    '#menu' => array(
            'width' => '250px',
            'height' => '300px',
            'background' => '#7f7'
    )

);

foreach ($css as $selector => $style) {
    echo "$selector { ";
    foreach ($style as $key => $value) {
            echo "'$key': '$value'; ";
    }
    echo "}\n";
}

IMO a much nicer way of doing the same thing, since the CSS actually makes sense when you're looking at the code as well. I suppose you could array_walk $css or whatever, but that's beside the point :p

Combine it with a css constants-parser and you have yourself a real winner.

level 2

I was just about the suggest this same thing only to find someone else already did... Thanks for saving me time!

level 1

terrible. stay away.

Community Details

1.4m

Subscribers

3.8k

Online

Computer Programming

Create Post
r/programming Rules
1.
Keep submissions on topic and of high quality
2.
No surveys
3.
No résumés/job listings
4.
/r/programming is not a support forum
5.
Spam
Info

Related reddits

Specific languages

Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies. Learn More.