Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: php in CSS

  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts

    php in CSS

    i have a file is called as style.css (like following ) it is separate file (not in any file)

    Code:
    .table
    	{
    
    		color:#CC0000;
    		border-spacing:1;
    		padding:0;
    		border: 0px solid;
    		width:75%; 
    		margin:1%;
    		text-align:center; 
    		margin-left:auto; 
    		margin-right:auto;
    		text-align:center;
    	}
    some value will be read from db.for example color value is $tbl_color

    is it possbile ?

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    by making the file included, so it ran through the php parser. Thats the only way, so you will have you css printed in the source of the page.
    Current Project: Nothing at the minute

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You're file will also need a .php extension or alteration in a .htaccess/http.conf file to include css as a php parsed file. I'd recommend sending a header at the top of you're css as well:
    PHP Code:
    <?php
    header
    ("Content-type: text/css");
    ?>
    body
    {
    ...
    }
    This way you do not need to include the file as long as its independent (doesn't rely on anything generated in another file, or uses the same file as another file), and you should be able to call it the same way:
    <link rel="stylesheet" type="text/css" href="mycss.php" />

    Been awhile since I've used an external stylesheet with php, but I seem to recall doing it this way and it worked no problems.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •