Can background image extend beyond div's borders?

后端 未结 7 1345
遥遥无期
遥遥无期 2020-12-05 10:05

Can background image extend beyond div\'s borders? Does overflow: visible apply to this?

7条回答
  •  生来不讨喜
    2020-12-05 10:19

    Following up on kijin's advice, I'd like to share my solution for image offsets:

    /** 
      * Only effective cross-browser method to offset image out of bounds of container AFAIK, 
      * is to set as background image on div and apply matching margin/padding offsets:
      */
    
    #logo {
      margin:-50px auto 0 auto;
      padding:50px 0 0 0;
      width:200px;
      height:200px;
      background:url(../images/logo.png) no-repeat;
    }
    

    I used this example on a simple div element

    to position my logo with a -50px vertical offset. (Note that the combined margin/padding settings ensure you don't run into collapsing margin issues.)

提交回复
热议问题