CSS Help - div over image

后端 未结 3 464
遥遥无期
遥遥无期 2020-12-22 08:54

I\'m making a small site for my college project, most of it is complete but I\'m stuck on how I should go about adding a feature.

If you go onto a site like http://w

相关标签:
3条回答
  • 2020-12-22 09:28

    Rhino's idea is a good one but you'll want to set footerbar's positioon to static so it stays inside the div.image

    .image {
        width: 200px;
        height: 150px;
        background-image: url("/images/whatever.jpg");
        position:inline-block;
        border:1px solid green;
    }
    .footerBar {
        position: static;
        bottom: 0px;
        width: 100%;
        overflow: none;
    }
    
    <div class="image">
        <div class="footerBar">[content]</div>
    </div>
    

    Otherwise you'd have to use javascript to find the position of the image relative to the page and absolute position the text where you wanted it with a higher z-index.

    0 讨论(0)
  • 2020-12-22 09:32

    How about having a master <div> with a background image?

    <div class="image" style="background-image: ('/images/whatever.jpg');">
        <div class="footerBar">[content]</div>
    </div>
    

    And style them with CSS, or use JavaScript to set the images.

    .image {
        width: 200px;
        height: 150px;
        position: relative;
    }
    .footerBar {
        background-color: lightGrey;
        position: absolute;
        bottom: 0px;
        width: 100%;
        overflow: none;
        display: none;
    }
    .image:hover .footerBar {
        display: block;
    }
    

    See example on jsFiddle

    0 讨论(0)
  • 2020-12-22 09:34

    Try setting position: absolute on the div you want to position over the image.

    0 讨论(0)
提交回复
热议问题