css背景图片适合div

时间:2012-05-27 03:39:54

标签: css image html background

  

可能重复:
  Stretch and Scale a CSS image Background - With CSS only

我想设置div背景图像div(宽度:1000,最小高度:710),图像大小为753 x 308 我试图设置它的图像不适合div大小我该怎么办?

.Invitation {
    background-color: transparent;
    background-image: url('../images/form.png');
    background-repeat: no-repeat;
    background-position: left top;
    background-attachment: scroll;
    background-size: 100%;
    width: 1000px;
    height: 710px;
    margin-left: 43px;
}

div类是

.content {  
   clear:both;  
   width:1000px;    
   background:#e7e8e9;
   background-image:url('../images/content.jpg');
   background-repeat:no-repeat;
   background-position:left top;
   min-height:710px;
}

,代码是

<div class="content"><div class="Invitation">form goes here....</div></div>

1 个答案:

答案 0 :(得分:7)

尝试这样的事情:

<强> CSS

<style type="text/css">
  img.adjusted {
    position: absolute;
    z-index: -1;
    width: 100%;
    top: 0;
    left: 0;
  }
  .Invitation {
    position: relative;
    width: 1000px;
    height: 710px;
    margin-left: 43px;
  }
</style>

<强> HTML

<div class="Invitation">
  This is an example
  <img src="http://files.myopera.com/arshamr/albums/612249/Nature%20(3).jpg" alt="" class="adjusted">
</div>

我希望这有帮助!