jarv Posted May 20, 2013 Share Posted May 20, 2013 hi, I am going through this tutorial: http://net.tutsplus.com/tutorials/php/supercharge-your-css-with-php-under-the-hood/ I have done what you said:here is my CSS page: <?php header('Content-type=text/css'); ?> #headcontainer { background-color: #<?php echo $headcontainerbg; ?> } here is my .htaccess (in the CSS folder) AddType application/x-httpd-php .html .htm .css AddHandler application/x-httpd-php .html .htm .css AddHandler application/x-httpd-php5 .css I am importing CSS stylesheet like my others I am using MAMP locally, still nothing Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/ Share on other sites More sharing options...
requinix Posted May 20, 2013 Share Posted May 20, 2013 header('Content-type=text/css');should be header('Content-type: text/css'); Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431269 Share on other sites More sharing options...
jarv Posted May 20, 2013 Author Share Posted May 20, 2013 ok, changed that thanks! still not working?! All my styles are broken Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431272 Share on other sites More sharing options...
Q695 Posted May 21, 2013 Share Posted May 21, 2013 Have the CSSes with identical names, and with a specific setting it will pull A, B, C to be output in the correct spot in the head of the page. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431298 Share on other sites More sharing options...
Eiseth Posted May 21, 2013 Share Posted May 21, 2013 What do you achieve with this anyway? Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431301 Share on other sites More sharing options...
DaveyK Posted May 21, 2013 Share Posted May 21, 2013 Use Less. It supports variables and you can just compile it on your machine using one of several free less compilers (SimpLess, WinLess, etc.) On 5/21/2013 at 4:49 AM, Eiseth said: What do you achieve with this anyway? You can use variables. Its great. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431312 Share on other sites More sharing options...
jarv Posted May 21, 2013 Author Share Posted May 21, 2013 please help, it's not working?! Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431322 Share on other sites More sharing options...
DaveyK Posted May 21, 2013 Share Posted May 21, 2013 Use Less, it was DESIGNED with this in mind. http://lesscss.org/ it works like this: @white: #fff; .div{ background-color: @white; } What else do you want?! Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431328 Share on other sites More sharing options...
mac_gyver Posted May 21, 2013 Share Posted May 21, 2013 just telling us that something you are doing is not working, doesn't help us to help you. you haven't even posted your code that is linking/including the .css file, so we have no idea what any of your code is doing. when you browse directly to the .css file, is the output in the browser what you expect? Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431329 Share on other sites More sharing options...
DaveyK Posted May 21, 2013 Share Posted May 21, 2013 On 5/21/2013 at 8:06 AM, mac_gyver said: just telling us that something you are doing is not working, doesn't help us to help you. you haven't even posted your code that is linking/including the .css file, so we have no idea what any of your code is doing. when you browse directly to the .css file, is the output in the browser what you expect? I think what he is trying to do is output a .css file from a .php file, which is redundant when you use Less. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431330 Share on other sites More sharing options...
mac_gyver Posted May 21, 2013 Share Posted May 21, 2013 not if the values are dynamic, such as custom styling stored in a database and are being retrieved using php code. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431332 Share on other sites More sharing options...
DaveyK Posted May 21, 2013 Share Posted May 21, 2013 Why would you store variables in a database. less can use different files, with a single file to import all of them to a single .css file. For one, I have this styles.less // this is the file that has the styles .h2{ color: @red; &.big{ width: @full_width; } } variables.less // this holds the variables @dark_red : #a30f0f; @red: #ff0000; @full_width: 980px; bootstrap.less // this combines both using @import "variables.less" and @import "styles.less" // Core variables and mixins @import "variables.less"; @import "styles.less"; With simpless or winless, if you compile that bootstrap.less file you will get a bootstrap.css file looking like this: bootstrap.css h2{ color: #ff0000; } h2.big{ width: 980px; } also, if one fetches styles from the database on load I would love to see the loading times. Less can be compiled on either the server (using JS) or on your machine, in which case you just upload the CSS. The time difference is little to none, tho for peace of mind I always use the latter. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431333 Share on other sites More sharing options...
mac_gyver Posted May 21, 2013 Share Posted May 21, 2013 Quote Why would you store variables in a database. one example would be so that each user could have his own settings. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431334 Share on other sites More sharing options...
DaveyK Posted May 21, 2013 Share Posted May 21, 2013 On 5/21/2013 at 8:27 AM, mac_gyver said: one example would be so that each user could have his own settings. Lol that was rather badly written by me. What else to store in a database than data. Regardless, I am assuming this is not the case and even if it is, less probably has a much cleaner solution. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431336 Share on other sites More sharing options...
mac_gyver Posted May 21, 2013 Share Posted May 21, 2013 On 5/20/2013 at 10:01 PM, jarv said: ok, changed that thanks! still not working?! All my styles are broken i was reading your thread on one of the other programming help forums where you started out the thread by stating that the .htaccess file breaks all your styles. that tutorial contains a comment that EVERY .css file in the folder where the .htaccess file is at must have the header() statement in it. only put your dynamically produced .css files in the folder with the .htaccess file. put regular .css files somewhere else. Link to comment https://forums.phpfreaks.com/topic/278225-how-can-i-write-css-with-php-i-tried-and-i-have-lost-styles/#findComment-1431337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.