Page 1 of 1

CSS sheet in PHP?

Posted: Sun Feb 05, 2006 11:31 am
by xEzMikex
whats the code to link a CSS style sheet to php?

Posted: Sun Feb 05, 2006 12:18 pm
by John Cartwright
its not actually php, php could output this though

Code: Select all

<link rel="stylesheet" href="/template/style.css" type="text/css">
or

Code: Select all

echo '<link rel="stylesheet" href="/template/style.css" type="text/css">';
is the "php way"

Posted: Sun Feb 05, 2006 12:53 pm
by highonsnow
You could also shave off a little overhead by avoiding the echo and simply doing this:

Code: Select all

?><link rel="stylesheet" href="/template/style.css" type="text/css"><?
Since PHP has no business with that string, why send it through the parser

Posted: Sun Feb 05, 2006 1:50 pm
by raghavan20
highonsnow wrote:You could also shave off a little overhead by avoiding the echo and simply doing this:

Code: Select all

?><link rel="stylesheet" href="/template/style.css" type="text/css"><?
Since PHP has no business with that string, why send it through the parser
jcart would have demonstrated the power of the PHP to use dynamic CSS dependent on conditions...

Posted: Sun Feb 05, 2006 2:17 pm
by highonsnow
I'm sure he didn't ask for that ability but with a little creativity you could simply:

Code: Select all

?><link rel="stylesheet" href="/template/<?echo $vars_template_name;?>/style.css" type="text/css"><?
Can't be too fussy ;)

Posted: Sun Feb 05, 2006 2:38 pm
by xEzMikex
either way thanks for both of your help :)

Posted: Sun Feb 05, 2006 2:56 pm
by Chris Corbyn
If you wanted your stylesheet to be dynamic you can also try this:

Code: Select all

<link rel="stylesheet" type="text/css" href="somescript.php?page=prices" />
... and the somescript.php file...

Code: Select all

<?php header('Content-type: text/css'); ?>

body {
    margin: 0;
    padding: 5px 20px;
    background-color: <?php
    
    switch ($_GET['page'])
    {

        case 'prices' :
        echo '#EEEEEE;';
        break;
        default:
        echo '#FFFFFF;';

    }

    ?>
}

div#foo {
    border: 1px dotted #AAAAAA;
}

/* etc etc etc */

Posted: Sun Feb 05, 2006 3:21 pm
by xEzMikex
allright well one more problem... its not reading.... :( this is the element im using.

Code: Select all

<link rel="stylesheet" href="/skin/ice_blue/index.css" type="text/css">
this is my style sheet code

Code: Select all

body{
	margin-top:5px;
	background-image:url(images/bg.gif);
	}
    div.banner{
	background-image:url(images/1_01.gif);
	color:#000000;
	margin:auto;
	height:100px;
	width:700px;
	top:0px;
	} 
	div.links{
	background-image:url(images/1_02.gif);
	color:#000000;
	margin:auto;
	height:14px;
	width:700px;
	font-size: 9px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	text-align: center;
	}
	div.content{
	background-image:url(images/1_03.gif);
	color:#000000;
	margin:auto;
	height:auto;
	width:700px;
	font-size: 9px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	text-indent:2px;
	}
	div.end{
	background-image:url(images/1_04.gif);
	color:#000000;
	margin:auto;
	height:2px;
	width:700px;
	}
and this is my directory setup

Code: Select all

|ROOT|
index.php
|SKIN|
   |IMAGES|
   index.css

Posted: Sun Feb 05, 2006 4:46 pm
by xEzMikex
.bump

Posted: Sun Feb 05, 2006 4:50 pm
by Chris Corbyn
xEzMikex wrote:.bump
:evil: DO NOT BUMP WITHIN 24 HOURS. That was ridiculuously soon after you replied! Nobody's obliged to respond to your thread, but bumping won't help if you come across impatient.

Posted: Sun Feb 05, 2006 5:35 pm
by Chris Corbyn
The images don't look like they've been referenced correctly.... is the entire CSS file not being imported or is it just the images?

href="/skin/ice_blue/index.css"

background-image:url(../images/bg.gif);

Posted: Sun Feb 05, 2006 5:39 pm
by xEzMikex
d11wtq wrote:The images don't look like they've been referenced correctly.... is the entire CSS file not being imported or is it just the images?

href="/skin/ice_blue/index.css"

background-image:url(../images/bg.gif);
sorry for the bump... uhm the images folder is in the ice_blue folder so i thought i only had to put "/images/<img>" he css file is being imported its just not the pitures i think.

EDIT i fixed it.. the element wasnt in the right place thanks for the help.

Posted: Sun Feb 05, 2006 5:52 pm
by highonsnow
Good stuff ;)