Maknib Posted August 24, 2011 Share Posted August 24, 2011 is itpossible to have php in an external css file? so my user could change the background color? something like.. body{ background: <?php $color; ?> } if it is would the .css file need to be a .css or .php cheers Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/ Share on other sites More sharing options...
doddsey_65 Posted August 24, 2011 Share Posted August 24, 2011 you cant include php code in a css file. You could use the php in a html document and create inline styling: <style type="text/css"> body { background-color: <?php echo $color; ?>; } </style> Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/#findComment-1261193 Share on other sites More sharing options...
PFMaBiSmAd Posted August 24, 2011 Share Posted August 24, 2011 You can either configure your server to parse .css files as php code (you need to be careful not to let users/hackers upload .css files that contain their php code) or you can use a .php file as the external css file and output a Content-type: text/css header at the start of the php code in the file. Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/#findComment-1261196 Share on other sites More sharing options...
Maknib Posted August 24, 2011 Author Share Posted August 24, 2011 you cant include php code in a css file. You could use the php in a html document and create inline styling: <style type="text/css"> body { background-color: <?php echo $color; ?>; } </style> thanks, i was thinking of that but i thought inline was frowned upon a bit. Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/#findComment-1261197 Share on other sites More sharing options...
doddsey_65 Posted August 24, 2011 Share Posted August 24, 2011 if its done right and kept within the <head> tags then there's nothing wrong with it Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/#findComment-1261198 Share on other sites More sharing options...
Maknib Posted August 24, 2011 Author Share Posted August 24, 2011 if its done right and kept within the <head> tags then there's nothing wrong with it ahh ok so <style> img { width: 300px; } </style> is fine but.. <img src="" style="width: 300px;" /> is out Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/#findComment-1261205 Share on other sites More sharing options...
erdem Posted August 24, 2011 Share Posted August 24, 2011 you can have style.css which can be #footer{ backgground:#<?php $color; ?> } } and include it include('style.css') maybe? Quote Link to comment https://forums.phpfreaks.com/topic/245556-php-is-stylesheets/#findComment-1261274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.