0

I want to show a png file in background of a div. I have this CSS style for put it in the correct place. I'v tested directly in my HTML and the style works properly. I't doesn't work wen I use php variable.

<?php 

    if ($RScoluna1['nova'] == 1){
        $style = "background-image:url(layout/nova.png); background-repeat:no-repeat; background-position: 220px 0;";
    } else {
        $style = "";
    }


    ?>
    <div class="<?php echo $row_RScoluna1['class_cor']; ?>" style="<?php echo $style; ?>">
5
  • 1
    are you sure that $RScoluna1['nova'] sometimes holds 1 as a value? Commented May 6, 2015 at 10:09
  • yes my first data row have 1 (mySQL INT) Commented May 6, 2015 at 10:10
  • Make sure the relative path to the image is working and the div has enough width and heigth to display the image. Commented May 6, 2015 at 10:12
  • 1
    Check the path of the files. Commented May 6, 2015 at 10:14
  • I'v checked. If you copy background-image:url(layout/nova.png); background-repeat:no-repeat; background-position: 220px 0; and past it on style="" it works Commented May 6, 2015 at 10:20

1 Answer 1

1

If you copy pasted

background-image:url(layout/nova.png)

from a css file, then you should fix the path accordingly to the position of the script.

In example:

background-image:url("../css/layout/nova.png");

I hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

My bad. if ($RScoluna1['nova'] == 1){ should be if ($row_RScoluna1['nova'] == 1){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.