Floating Div Over An Image

前端 未结 5 969
耶瑟儿~
耶瑟儿~ 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:42

    Actually just adding margin-bottom: -20px; to the tag class fixed it right up.

    http://jsfiddle.net/dChUR/7/

    Being block elements, div's naturally have defined borders that they try not to violate. To get them to layer for images, which have no content beside the image because they have no closing tag, you just have to force them to do what they do not want to do, like violate their natural boundaries.

    .container {
      border: 1px solid #DDDDDD;
      width: 200px;
      height: 200px;
      }
    .tag {
      float: left;
      position: relative;
      left: 0px;
      top: 0px;
      background-color: green;
      z-index: 1000;
      margin-bottom: -20px;
      }
    

    Another toue to take would be to create div's using an image as the background, and then place content where ever you like.

    BLAH BLAH BLAH

提交回复
热议问题