Re: Creating a Dynamic PHP/CSS Page (newbie design question)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2009-11-05 at 14:13 -0600, Shawn McKenzie wrote:

> cool@xxxxxxxxxxxxxxxx wrote:
> > SORRY FOR THE EXTRA 2 BAD pre SENDS (accident...)
> > 
> > 
> > Thank for all the help!
> > 
> > Getting there... as a baby step - I'm trying this:
> > 
> > (part of this is from - http://sperling.com/examples/pcss/)
> > 
> > 1 - I created this style sheet page called css.php with these contents:
> > 
> > ================
> > 
> > .test1 {
> >     font-family: Verdana, Arial, Helvetica, sans-serif;
> >     color: #0099FF;
> >     font-size: 18px;
> > }
> > 
> > <?php
> > header("Content-type: text/css");
> > $color = "green";        // <--- define the variable
> > echo <<<CSS
> > /* --- start of css --- */
> > .title-text
> >     {
> >     color: $color;  /* <--- use the variable */
> >     font-weight: bold;
> >     font-size: 1.2em;
> >     text-align: left;
> >     }
> > /* --- end of css --- */
> > CSS;
> > ?>
> > 
> > -------------------------
> > 
> > 2 - I created this test page called testcss.php with these contents:
> > 
> > PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't seem
> > to work
> > btw: even added this : media="screen" from demo ....
> > How do I get it to show up?
> > 
> > ======
> > 
> > 
> > 
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> > <html xmlns="http://www.w3.org/1999/xhtml";>
> > <head>
> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
> > <title>Untitled Document</title>
> > 
> > <link href="css.php" rel="stylesheet" type="text/css" media="screen" />
> > </head>
> > 
> > <body >
> > <p>test <span class="test1">this</span></p>
> > 
> > <p class="title-text">and this</p>
> > </body>
> > </html>
> > 
> > 
> > ===================
> > 
> > 
> > Thanks,
> > cool@xxxxxxxxxxxxxxxx
> 
> You need to do the header() before anything else.
> 
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com
> 


Like I mentioned in my first reply to this, you need to set the content
type of the output in css.php:

header("Content-Type: text/css");

That way, the server sends down the right headers to the agent that is
requesting the CSS. By default, PHP outputs a content type of text/html,
and your browser thinks it got HTML instead of CSS so does nothing.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux