Jump to content

css in php echo


RealDrift

Recommended Posts

Hi,

 

I want to echo the following but want the font to adhere to the css rules I have defined in a file called in.css

 

Here is the echo:

 

echo "<span class=\"output.reward\">You Donated!</span>";

 

Before this echo I put the following line to include the css file:

 

echo "<link rel=stylesheet href=includes/in.css type=text/css>";

 

the css thing is called output.reward and is in the in.css file like so:

 

output.reward  {  
  font-size: 10px;  
font-family: Verdana;
  color: #FFCC00;

}

 

The problem is the echoed font is not what the css rule is defined as.

 

Any help would be good.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/168458-css-in-php-echo/
Share on other sites

The style sheet has to be between the head tags of your page...

 

<html>
<head>

<?php
echo '<link rel="stylesheet" href="includes/in.css" type="text/css" />';
?>

</head>
<body>

<?php
echo '<span class="reward">You Donated!</span>';
?>

</body
</html>

 

Also you may have noticed that I changed the class name, a class name can't have a period in it... Also to let the css file know you're using it as a class (rather than an element, or id) it needs a period at the start as follows:

 

.reward  {  
  font-size: 10px;  
font-family: Verdana;
  color: #FFCC00;

}

Link to comment
https://forums.phpfreaks.com/topic/168458-css-in-php-echo/#findComment-888602
Share on other sites

Thanks for the quick reply, I gotta go to bed now - its 2:46am here and i gotta get an early start lol

 

I'll test your method tommorow. I wanted to know if everytime I want to use css font rules in a php echo I have to put them in <body> tags and such? or is there another simpler way?

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/168458-css-in-php-echo/#findComment-888609
Share on other sites

I have done as you suggested but the echoed sentence is still not what the css says it should be.

make sure your in.css is in includes folder.

 

if still not working try to use inline style. like

 

echo "<span style='font-family:Verdana, Geneva, sans-serif;font-size:10px;color:#ffcc00'>You Donated!</span>";

Link to comment
https://forums.phpfreaks.com/topic/168458-css-in-php-echo/#findComment-891840
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.