CSS sheet in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xEzMikex
Forum Commoner
Posts: 38
Joined: Sat Jan 21, 2006 10:18 pm
Location: Canada

CSS sheet in PHP?

Post by xEzMikex »

whats the code to link a CSS style sheet to php?
Last edited by xEzMikex on Sun Feb 05, 2006 3:21 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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"
highonsnow
Forum Newbie
Posts: 5
Joined: Sat Feb 04, 2006 1:59 pm

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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...
highonsnow
Forum Newbie
Posts: 5
Joined: Sat Feb 04, 2006 1:59 pm

Post 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 ;)
xEzMikex
Forum Commoner
Posts: 38
Joined: Sat Jan 21, 2006 10:18 pm
Location: Canada

Post by xEzMikex »

either way thanks for both of your help :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 */
xEzMikex
Forum Commoner
Posts: 38
Joined: Sat Jan 21, 2006 10:18 pm
Location: Canada

Post 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
xEzMikex
Forum Commoner
Posts: 38
Joined: Sat Jan 21, 2006 10:18 pm
Location: Canada

Post by xEzMikex »

.bump
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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);
xEzMikex
Forum Commoner
Posts: 38
Joined: Sat Jan 21, 2006 10:18 pm
Location: Canada

Post 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.
highonsnow
Forum Newbie
Posts: 5
Joined: Sat Feb 04, 2006 1:59 pm

Post by highonsnow »

Good stuff ;)
Post Reply