3

I want to use the bootstrap half-slider carousel and I am using codeigniter. In it, it used <div> with background-image instead of <img>, like this

<div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide One');"></div> 

In my view used it like this:

<div class="fill" style="background-image:url('../assets/images/image1.jpg')"></div>

However, it doesn't show the image.

Your help will be much appreciated.

d_unknown
  • 875
  • 3
  • 15
  • 41
  • is your assets folder in your main directory? –  Jan 03 '16 at 10:58
  • @wolfgang1983, my assets folder is outside application folder of codeigniter.. – d_unknown Jan 03 '16 at 11:32
  • I would create a css file in the assets folder then add it to the head area add that style in css there and should work. –  Jan 03 '16 at 11:53
  • @wolfgang1983, I actually have 5 images in the slider. Do you mean, I have to make 5 classes with different background images? – d_unknown Jan 03 '16 at 12:11

1 Answers1

0

Not sure how you have structured your view files, but the reason why the first one is working is probably because it have an absolute path for the image ('http://placehold.it/1900x1080&text=Slide One')

Try using an absolute path to you image in the assets folder. Instead of: <div class="fill" style="background-image:url('../assets/images/image1.jpg')"></div>

Try:

<div class="fill" style="background-image:url('<?=base_url('assets/images/image1.jpg')?>')"></div>

Elymentree
  • 823
  • 10
  • 22