Jump to content

How can I write CSS with PHP? - I tried and i have lost styles


jarv

Recommended Posts

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
Share on other sites

Use Less. It supports variables and you can just compile it on your machine using one of several free less compilers (SimpLess, WinLess, etc.)

 

 

 

What do you achieve with this anyway?

 

 

You can use variables. Its great.

Edited by DaveyK
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.

Edited by DaveyK
Link to comment
Share on other sites

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.

Edited by DaveyK
Link to comment
Share on other sites

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.

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.