Floating Div Over An Image

前端 未结 5 970
耶瑟儿~
耶瑟儿~ 2020-12-04 13:06

I\'m having trouble floating a div over an image. Here is what I am trying to accomplish:

5条回答
  •  误落风尘
    2020-12-04 13:36

    Change your positioning a bit:

    .container {
        border: 1px solid #DDDDDD;
        width: 200px;
        height: 200px;
        position:relative;
    }
    .tag {
        float: left;
        position: absolute;
        left: 0px;
        top: 0px;
        background-color: green;
    }
    

    jsFiddle example

    You need to set relative positioning on the container and then absolute on the inner tag div. The inner tag's absolute positioning will be with respect to the outer relatively positioned div. You don't even need the z-index rule on the tag div.

提交回复
热议问题