How to place a div on top of a image

Discussion in 'CSS' started by ponpulla, Oct 20, 2010.

  1. #1
    ive been trying to place my div on top of a image, i know its possible but havent figured it out best i do is make my image the backgrounds and lower it with < br> </ br> codes
    and space for the left right lol but this is no longer feasable


    i need to be able to place my div on the of the image at a spefic location say


    -------------------------------------


    This is my image



    ------------------------------------


    ------------------------------------

    This is my image

    [DIV HERE]
    -----------------------------------

    thanks for any help
     
    ponpulla, Oct 20, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are a few other ways but I like this one:
    
    <html>
    <head>
    <style type='text/css'>
    #imageBox {
       background: url('image.jpg') no-repeat;
       height: 100px;
       margin-bottom: 50px;
       position: relative;
       width: 100px;
    }
    
    #content {
       bottom: 0;
       position: absolute;
    }
    </style>
    </head>
    <body>
    <div id='imageBox'></div>
    <div id='imageBox'>
       <div id='content'>Text</div>
    </div>
    </body>
    </html>
    
    Code (markup):
     
    Cash Nebula, Oct 20, 2010 IP
  3. ponpulla

    ponpulla Peon

    Messages:
    538
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Thanks alot man really simple man,


    EDIT: one problem doesnt show in IE
     
    Last edited: Oct 20, 2010
    ponpulla, Oct 20, 2010 IP
  4. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Dang! :eek: I repeated an ID, maybe that was the problem. Just change them to classes.

    Another way is to apply margins or paddings, but that can be more trouble than positioning.
    
    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
    <html>
    <head>
    <style type='text/css'>
    .imageBox {
       background: url('image.jpg') no-repeat;
       height: 50px;
       margin-bottom: 20px;
       width: 100px;
       padding-top: 50px;
    }
    </style>
    </head>
    <body>
    <div class='imageBox'>
       <p>Text</p>
    </div>
    </body>
    </html>
    
    Code (markup):
     
    Cash Nebula, Oct 20, 2010 IP
  5. ponpulla

    ponpulla Peon

    Messages:
    538
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Thanks man again....
     
    ponpulla, Oct 22, 2010 IP
  6. kefutiwi

    kefutiwi Member

    Messages:
    118
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #6
    i think your question has already been answered, but just to clarify, it is best that you absolute position elements within a parent container when you want them to overlap something else
     
    kefutiwi, Oct 23, 2010 IP
  7. Monty251

    Monty251 Active Member

    Messages:
    189
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    What you can do is delete the image, place a div and put the background image of the div as your image. Simple :)
     
    Monty251, Oct 23, 2010 IP
  8. kevin.truong

    kevin.truong Peon

    Messages:
    161
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    i have the same question but now i found the anwers.Thanks
     
    kevin.truong, Oct 23, 2010 IP
  9. Suukai

    Suukai Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    "z-index" can also be used to layer things. Its very handy.
     
    Suukai, Oct 24, 2010 IP