Html css 背景图片适合 div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10771481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:40:18  来源:igfitidea点击:

css background image fit to div

cssimagehtmlbackground

提问by Rekha Prabhu

Possible Duplicate:
Stretch and Scale a CSS image Background - With CSS only

可能的重复:
拉伸和缩放 CSS 图像背景 - 仅使用 CSS

I want to set div background image div(width: 1000, min-height: 710) and the image size is 753 x 308 whan I trying to set it image is not getting fit to the div size what should i do?

我想设置 div 背景图像 div(width: 1000, min-height: 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;
}

The div class is

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;
}

and the code is

代码是

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

回答by Marco Godínez

Try something like this:

尝试这样的事情:

CSS

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

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>

I hope this helps!

我希望这有帮助!