Php in style tags

Hello All,

is it possible to use php in style.

I am getting a value in php script like this :

$profile_pic1 = '<img src="user/shail/'.$avatar.'" width="200" height="200">';

In body i am calling it in style:


<head>
<style>
 #small{
    height:200px; width:200px;
    background-image:url(<?php echo $profile_pic1; ?>);
    background-size:cover;
 }
</style>
</head>
<body>
<div id="small"></div>
</body>

But nothing is visible.

Thanks
Shail

Try this:



<style>
 #small{ 
    height:200px; width:200px;
    background-image:url(<?php echo $avatar;?>);
    /* background: snow url(< ?php echo $avatar;? >); */
    background-size:cover; 
 }
</style>


also Google for the “CSS background image” and find the options

Hello!

You have a problem within your CSS syntax:

 background-image:url([B] HERE MUST BE THE URL OF YOUR IMAGE - NOT <img src... [/B]);

So please change the $profile_pic1 to:

$profile_pic1 = 'user/shail/'.$avatar; 

If the problem prospers:

  1. Be sure that your file ends with “.php”
  2. Be sure the “$profile_pic1” variable is declared first, before of “echo”.
  3. Echo the variable as simple text and check if it is ok.
  4. If you can’t see the background image, there couldn’t be a PHP problem. Right-Click and View source on the page an check if PHP echo the image url.

You might be interested in SASS or LESS