homepage Welcome to WebmasterWorld Guest from 54.205.247.203
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
CSS in PHP Problem
Can't seem to apply these styles...
madcat




msg:1314200
 5:09 am on Aug 25, 2002 (gmt 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

 

jatar_k




msg:1314201
 6:07 am on Aug 25, 2002 (gmt 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.

Nick_W




msg:1314202
 7:44 am on Aug 25, 2002 (gmt 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

madcat




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

This was something to do with CSS- my bad.

lorax




msg:1314204
 4:39 pm on Aug 25, 2002 (gmt 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>
?>

madcat




msg:1314205
 5:27 pm on Aug 25, 2002 (gmt 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?

brotherhood of LAN




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

<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

Nick_W




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

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

Nick

lorax




msg:1314208
 6:36 pm on Aug 25, 2002 (gmt 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]

Nick_W




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

Or the short-hand:

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

Nick

lorax




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

<?=$myclass;?>

Did you really mean to use that equal sign?

jatar_k




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

yes, it just echos the value of the enclosed variable.

Nick_W




msg:1314212
 7:01 pm on Aug 25, 2002 (gmt 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

madcat




msg:1314213
 7:32 pm on Aug 25, 2002 (gmt 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

madcat




msg:1314214
 7:48 pm on Aug 25, 2002 (gmt 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?

lorax




msg:1314215
 9:20 pm on Aug 25, 2002 (gmt 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?

madcat




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

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

Just caught the tricks part lorax ;)

copongcopong




msg:1314217
 2:31 am on Aug 26, 2002 (gmt 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!

madcat




msg:1314218
 5:30 am on Aug 26, 2002 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved