I need to set a background image for the div below. The background image must be assigned as as inline style. I must use php to do this. However, with the way the quotes in html, css inline styles, and php are my method below does not work. I was wondering if someone can help me fix this? Many thanks in advance!
$form .= '
<div class="notes" style="background:url(\'http://i47.tinypic.com/d9897p.png\');" >Hello</div>';
$form .= '<div class="notes" style="background:url(http://i47.tinypic.com/dre2cp.png);">Hello</div>';
Your inline css is correct. Give a minimum height and width so you can see your image:
$form .= '<div class="notes" style="background:url(http://i47.tinypic.com/dre2cp.png); min-height: 400px; min-width: 400px;">Hello</div>';
It may be not working because http://i47.tinypic.com/d9897p.png is a 404-Not Found.
The below does appear to work, but returns the 404 image.
<div style="background-image:url(http://i47.tinypic.com/d9897p.png); min-height:300px; min-width:300px;"> </div>
Avoid printing HTML via PHP strings. Just leave it as is.
there is not a single reason for having $form
variable.
HTML should be written as it (after closing PHP tag of course)
<div class="notes" style="background:url('http://i47.tinypic.com/d9897p.png');" >Hello</div>