Jump to content


Photo

CSS and PHP


  • Please log in to reply
29 replies to this topic

#1 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 23 September 2006 - 03:37 AM

How would I do something like this in CSS with PHP?  It doesn't work, but surely you can understand what I want:

#topnav  {
	background:url($path/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}


#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 23 September 2006 - 03:39 AM

ok try

#topnav  {
	background:url(<?php$path?>/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}


#3 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 23 September 2006 - 03:40 AM

sorry, no dice


#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 23 September 2006 - 03:43 AM

have u defined the $path???

try this i know wat went wrong there

<?php
Echo("
#topnav  {
	background:url($path/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}
");
?>


#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 23 September 2006 - 03:44 AM

^ Yea that would work as well but I already had this type so here you go...

#topnav  {
	background:url(<?php echo $path; ?>/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}

Hope that works for you.

Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 23 September 2006 - 03:54 AM

neither works :(

#7 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 23 September 2006 - 04:02 AM

then your not defining the varible $path

#8 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 23 September 2006 - 04:14 AM

I agree. Also, are you renameing the css file to php?

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#9 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 23 September 2006 - 04:25 AM

No steelman is correct. It does not work that way...

You have to define the path not set a variable. So somewhere you have to do this.
define(path, 'http://www.yoursite.com', true);

now you can do this in the css file. Once again you have to change the extentsion to php

#topnav  {
	background:url(<?php path ?>/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}

I tested this and it works fine..

Sorry that i said that you were wrong before testing it my self.

Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#10 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 23 September 2006 - 08:57 AM

You could use sessions.

index.php:
<?php
session_start();
$_SESSION['path'] = "/home/you/public_html/something";
echo <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>Test site</title>
<link rel="stylesheet" type="text/css" href="stylesheet.php />
</head>
<body>

<!-- some html here -->

</body>
</html>

EOF;
?>

stylesheet.php:
<?php
session_start();
header("Content-type: text/css");
echo <<<EOF
#topnav {
	background:url({$_SESSION['path']}/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}

EOF;
?>


#11 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 23 September 2006 - 04:05 PM

okay. I had $path = .;  so that the file looked like ./includes/teal.gif but I guess I need to do:

define(path, '.', true);

#12 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 23 September 2006 - 04:24 PM

yea that is what I did and it works fine.  Once again I am sorry for telling you that you were doing something wrong before testing it my self..

Good luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#13 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 24 September 2006 - 08:18 PM

Okay, just gave this a test and it doesn't work :(

index.php
<?php
$path = ".";

define(root, '.', true);

include($path.'/includes/overall_header.inc');

echo '<h1>Blah</h1>';

include($path.'/includes/overall_footer.inc');

?>


style1.css
#topnav  {
	background:url(<?php root ?>/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}

I know I have all the paths defined correctly :(

#14 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 25 September 2006 - 01:09 AM

I don't know what to tell you. It worked fine for me. The only difference was that I defined the entire url. May be you should try that instead of just ( . )


Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#15 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 25 September 2006 - 02:23 AM

I think your file style1.css should be renamed to style1.php (so it can execute the php code).
do it, do it right, do it right now

#16 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 02:32 AM

For starters the first argument define excepts is a string, not a constant.

define("root",".");

However... constant or not, this has nothing to do with your problem. This...

#topnav  {
	background:url(<?php echo $path; ?>/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}

is perfectly legitimate code if your css file has the .php extension. You may also need to define the mime type however. Place this at the top.

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


#17 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 28 September 2006 - 07:54 PM

okay, now I can't even get they stylesheet to call. Here is what I have:

index.php
<?php

ob_start();
define(root, '.', true);

$path = ".";


//require the headers
require_once('includes/headers.php');

// require the database connection
require_once('includes/db.php');

//Require functions.php
require_once('includes/functions.php');

// require the top layout
require_once('includes/top.php');

top.php
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>

<!--BEGIN META-->

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<meta name="Keywords" content="free linux tutorials, free apache tutorials, free php and mysql tutorials, live forums, free classes, free forums, programming help, php help, mysql help, apache help, free php help, php tutorials" />

<meta name="Description" content="LAMPGeekz offers free news, tutorials, classes, and live forums in Linux, Apache, MySQL, PHP, and more! Get all of your programming help here!" />

<!-- Begin Stylesheets -->
<?php
echo "
<link rel='stylesheet' type='text/css'  href=$path.'/includes/style1.php' />
<link rel='stylesheet' type='text/css'  href=$path.'/includes/style1.php' media='print' />
";
?>

I renamed the stylesheets as style1.php and style2.php just as said.

style1.php
/* CSS Document */

body  {
	font-family:Verdana, arial, times, helvetica, arial, sans-serif;
	margin:0;
	padding:0;
	font-size:78%;
}

a {
	text-decoration:none;
}

a:hover {
	text-decoration:underline;
}	

code {
	font-family:Verdana, arial, times, helvetica, arial, sans-serif;
	font-size:76%;
}

dt {
	font-weight:bold;
}

pre {
	font-family:Verdana, arial, times, helvetica, arial, sans-serif;
	font-size:76%;
}

/************************    HEADER TEXT  ************/
#title  {
	font-size:1.9em;
	font-family:Georgia, verdana, arial, helvetica, arial, sans-serif;
	padding-left:100px;
	font-weight:normal;
	margin-top:10px;;
}
/**********************    NAVIGATION IN TOP-RIGHT CORNER   *****/
#cornernav  {
	float:right;
	margin-top:5px;
	margin-right:5px;
}

#cornernav a {
	color:#686868;
	padding-right:20px;
}
/***************************   INLINE NAVIGATION   WRAPPER     *****/
#navwrap  {
	position:relative;
	padding-top:1px;
	padding-bottom:1px;
	border-top:3px solid #888;
	border-bottom:2px solid #888;
}
/*****************************   INLINE NAVIGATION   *********/

#topnav  {
	background:url(<?php root ?>/includes/teal.gif) repeat-x;
	padding-top:5px;
	color:#fff;
}



#topnav ul
{
	height:2.4em;
	line-height:2.4em;
	list-style: none;
	padding:0;
	margin:0;
}

#topnav li
{
	float: left;
}

#topnav li a
{
	line-height:2.4em;
	float:left;
	width:80px;
	display: block;
	color: #fff;
	text-align: center;
}
/****************************    INPUT BUTTONS  ********/
input.side, input.blue  {
	width:100px;
	background-color:#77abb8;
	font-weight: bold; 
	font-size:1em; 
	margin-top:2px;
	color: #f0f0f0;
	margin-left:20px;
	height:23px;
}

input.blue {
	width:40px;
}
/****************************    SEARCH BAR   ************/
#search {
	position:absolute;
	top:5px;
	right:10px;
}	



/******************************   SIDE NAVIGATION     ****/
#sidenav    {
	float:left;
	margin-left:20px;
	margin-top:20px;
	width:200px; 
	border-left:1px solid #c4c4c4;
	border-right:1px solid #c4c4c4;
	border-bottom:1px solid #c4c4c4;
}

#sidenav ul  {
	list-style-type:circle;
}

#sidenav p.search  {
	padding-left:1em;
	padding-bottom:10px;
}

#sidenav  li  {
	padding-top:0.6em !important;
	padding-top:0.4em;
}

#sidenav li a {
	color:#000;
}

#sidenav li a:hover  {
	color:#2279af;
}


#sidenav h2 {
	font-size:100%;
	background:url(<?php root ?>/includes/teal.gif);
	color:#fff;
	height:1.8em;
	line-height:1.8em;
	padding-left:15px;
	margin-top:0;
}

/*************************    MAIN CONTENT AREA  ******* */
#content   {
	width:66%;
	float:left;
	margin-left:30px;
	margin-top:20px;
}


#content  p {
	text-indent:20px;
}

#content a {
	color:#77aab8;
	text-decoration:none;
}

#content a:hover {
	text-decoration:underline;
}

#content img {
	float:left;
}


#content h1 {
	height:1.8em;
	line-height:1.8em;
	background:url(<?php root ?>/includes/grey.gif) repeat-x;
	border-top:1px solid #c4c4c4;
	margin-top:0;
	font-size:1.2em;
	color:#000;
	padding-left:5px;
}

/*  *************************    FOOTER   *****************  */
#footer  {
	clear:both;
	height:3em;
	border-top:1px solid #77abb8;
	text-align:center;
	color:#000;
	margin-top:2em;
	font-size:.8em;
}

#footer a {
	color:#000;
}

#ads {
	clear:both;
	height:3em;
	text-align:center;
}

style2.php
/* CSS Document */

#sidenav, #topnav, #navwrap, #cornernav {
	display:none
}

#content h1 {
	background:#fff;
	border:0;
}	

#content {
	width:100%;
}	

#title {
	text-align:center;
}

#footer {
	border:0;
}	


sorry it took so long to test.  you posted your solutions and I haven't had time to do any coding on top of homework, work, and college activities.

#18 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 29 September 2006 - 02:20 AM

*bump*

#19 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 02 October 2006 - 08:11 PM

anyone able to help me with this one?

#20 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 03 October 2006 - 08:41 PM

*BUMP!*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users