Stretch a background image in IE8

前端 未结 7 798
时光说笑
时光说笑 2020-12-14 13:29

I\'m trying to stretch a background image to 100% width and height of the parent div. background-size is not supported in IE8 of-course. I tried the following code but it\'s

相关标签:
7条回答
  • 2020-12-14 13:52

    This (demo) does the trick (digestable version of css-only technique #2 from http://css-tricks.com/perfect-full-page-background-image/):

    <div class="background-size_cover">
      <img src="images/body_background2.png">
    </div>
    

    and

    .background-size_cover {
      top: -50%;
      left: -50%;
      width: 200%;
      height: 200%;
      position: relative;
    }
    .background-size_cover img {
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      margin: auto;
      min-width: 50%;
      min-height: 50%;
      position: absolute;
    }
    

    You'll want to make sure that the parent div is overflow: hidden; besides having whatever dimensions you want the image to get stretched to fit in.

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