www.webdeveloper.com
Results 1 to 6 of 6

Thread: Content & Background-Image

  1. #1
    Join Date
    Jul 2012
    Posts
    16

    Content & Background-Image

    So I am simply trying to display an image in a div tag. CSS is external, and I know the image path is correct because it works using content: url('my_url'); but doesn't work using background-image: url('my_url');

    Any suggestions?

    Perhaps just use 'content'? However, I'd like to repeat it horizontally...

    CSS
    Code:
    #banner {
    content: url('my_url'); <!-- works!!!! -->
    background-image: url('my_url'); <!-- doesn't work!!! -->
    background-repeat: repeat-x;
    position: absolute;
    bottom: 0;
    }
    HTML
    HTML Code:
    <div id="banner"></div>

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    868
    Just looking at this, I would have to guess that setting the background-image property doesn't seem to work because the <div> has no content, thus has no size. So there is a background, but the <div> itself is not really visible. Have you tried setting the width/height of the <div> as well when setting the background-image?

    Alternatively, you could add &nbsp; inside of the <div>. Since it's a block element it will fill the width of its parent, but with nothing inside it there is no height.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Jul 2012
    Posts
    16
    I just tried all of those suggestions, and the image is still not being displayed.

    Content works again, but no luck with background-image.

  4. #4
    Join Date
    Jul 2012
    Posts
    16
    I also added a style tag in the head tag with the same css code, and still not displaying... perhaps it's an issue with the CSS??

  5. #5
    Join Date
    Jul 2012
    Posts
    16
    Okay, I got the image to display by adding the original height and width of the image to the css. Now how do I get the image to repeat horizontally??

    Thank you thus far!!

  6. #6
    Join Date
    Jul 2012
    Posts
    16
    Figured it out. If you set the height to the preferred height in the css, and the width to 100% [or particular width] in the css, it works. Simply didn't set the height or width property.

    Thank you Sup3rkirby!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles