Image is not loaded as background

Asked

Viewed 127 times

0

Hello, I have the following code as part of my index.php

<style>
  #backgroundImage{
    background-image: url('<?=base_url();?>bg.jpg');
  }
</style>
<body id='backgroundImage'>
</body>

But the image is not being loaded. I have a default image called.jpg background that loads, but if I change the name of the image it does not load. Both images are on the right path.

  • There is a bg.jpg image, but it is not rendered

2 answers

0

The CSS part is not written correctly, the style in general is better to reference by class and not id, as is done in Javascript. And yet, there is a better way to locate the image using Codeigniter function. Whereas bg.jpg is at the root of your site, do the following in your view:

<html>
    <header>
        <style>
            body { background-image: url("<?=base_url('bg.jpg')?>"); }
        </style>
    </header>
    <body>
        <!-- a imagem estará aqui -->
    </body>
</html>

0

In the image path, you do not need the quotation marks. In this case also no, but you must concatenate with the image name.

<style>
  #backgroundImage{
     background-image: url(<?=base_url().'bg.jpg'?>);
  }
</style>

<body id='backgroundImage'></body>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.