Welcome to WebmasterWorld Guest from 50.19.190.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

CSS in PHP Problem

Can't seem to apply these styles...

     
5:09 am on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


Can you apply CSS styles to elements directly in a PHP script?

In one style sheet I set the look for list items in menu.php, but after adding some more list items- I wanted to change the look and feel of those additions. I tried making another class for them and adding them in menu.php, but it was a no go.

Do you have to leave PHP mode in order to apply styles in a script?

Thanks

6:07 am on Aug 25, 2002 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


I don't completely understand the post madcat.

You can use css the same with php as you do with straight html.

Can you clarify a bit? It sounds like you are having a css prob not php. What do you mean by leave php?

If you mean ?> and then do the css stuff and then <? then that is probably true. Not totally sure what you mean.

7:44 am on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


I think he's trying to apply styles between the <? ?> php tags.

If you are, then you should definately leave php, css is er.... css, not php, so you use it like you would normally regardless of php/asp or anything else...

Nick

2:46 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


This was something to do with CSS- my bad.
4:39 pm on Aug 25, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


Can you apply CSS styles to elements directly in a PHP script?

Technically yes you can but you need to escape your quotes for ids and classes:

<?php
<a href=\"somedoc.php\" class=\"mylink\">My Page</a>
?>

5:27 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


Thanks- that was the orignal problem I think- I just used single quotes to make it happen.

Is the code above the preferred way?

5:50 pm on Aug 25, 2002 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


<a href=\"somedoc.php\" class=\"mylink\">My Page</a>

This is what I hope to do with PHP...$somedoc.css being the variable.

Madcat, if you want CSS to apply to a certain area, just use PHP to output that particular style in your head section. Otherwise just break out of PHP and use "normal" HTML code

5:59 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


....and I thought I had the monoploly on confusing posts ;)

Nick

6:36 pm on Aug 25, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


....and I thought I had the monoploly on confusing posts

Nick, it seems you've forgotten some of mine! ;)

Is the code above the preferred way?

There really isn't a preferred way as it really depends upon what you're trying to do. As BOL said, if you were using a var to indicate which CSS sheet to call you could write the same link as

<body>
<a href="somedoc.php" class=<?php echo $myclass; ?>>My Page</a>
</body>

Or you could wrap you're php script around the link like this:

<?php
if ($somevar == $anothervar) {
?>
<a href="somedoc.php" class="mylink">My Page</a>
<?php
}
else
?>
<h4>No Link Available</h4>
<?php
//the rest of your php script...

[edited by: lorax at 6:48 pm (utc) on Aug. 25, 2002]

6:42 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Or the short-hand:

<body>
<a href="somedoc.php" class="<?=$myclass;?>">My Page</a>
</body>

Nick

6:45 pm on Aug 25, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


<?=$myclass;?>

Did you really mean to use that equal sign?

6:53 pm on Aug 25, 2002 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


yes, it just echos the value of the enclosed variable.
7:01 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Here's another use one you might not know...


$header=<<<EOF

<html>
<head>
<title>My title</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>

EOF;

Notice there is no need to escape anythint and you can also use vars inside the EOF's and I think function calls...

Nick

7:32 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


Here's another use one you might not know...

Isn't that the story;)

I simply created sub-classes and applied them correct:

li.sub_net{
font: .9em verdana, helvetica, sans-serif;
background: #ffc;
padding: 6px 0 6px 10px;
}

echo ("<li><a href='index.html?networking=1'>" . "Networking" ."</a></li>");
if (isset($_GET['networking'])) {
echo ("<li class='sub_net'><a href='index.html' class='sub_net'>" . "Pricing" . "</a></li>");
}

Great suggestions for implementing style above.

M

7:48 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


Anybody using Opera 6+?

When you click on any menu item (php menu) in my profile page the top logo image flickers and you can see the background come through.

What might be causing this considering the two are totally independent?

9:20 pm on Aug 25, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


Where were you guys when I started a thread about tips & tricks! :)

Madcat, I'm using Op 6.03 and I don't see what you're seeing. Anomoly?

9:50 pm on Aug 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


lol - Wouldn't surprise me if my copy of Opera ain't singin' a nice toon.

Just caught the tricks part lorax ;)

2:31 am on Aug 26, 2002 (gmt 0)

Full Member

10+ Year Member

joined:May 9, 2002
posts:241
votes: 0


remember that putting the css or typing the code itself as html is faster (miliseconds) than using php (like "echo") to put them ... but for functionality, ... go with php ... :) talk about conflicting answers!
5:30 am on Aug 26, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 15, 2002
posts:971
votes: 0


lol - this line of work can get pretty darned tangled.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members