Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

CSS in PHP Problem

Can't seem to apply these styles...

     

madcat

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

WebmasterWorld Senior Member 10+ Year Member



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

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

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



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

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

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



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

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

WebmasterWorld Senior Member 10+ Year Member



This was something to do with CSS- my bad.

lorax

4:39 pm on Aug 25, 2002 (gmt 0)

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



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

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



<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

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

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



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

Nick

lorax

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

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



....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

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

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



Or the short-hand:

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

Nick

lorax

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

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



<?=$myclass;?>

Did you really mean to use that equal sign?

jatar_k

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

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



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

Nick_W

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

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



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

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



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

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

WebmasterWorld Senior Member 10+ Year Member



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

Just caught the tricks part lorax ;)

copongcopong

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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