背景不是100%的容器div,相对绝对定位与百分比

时间:2013-07-19 14:11:37

标签: css position

我正在使用带有亲戚关系的页面绝对定位和百分比。 HTML&正文设置为100%,容器div是相对的,内部div是绝对的。我设置为容器div的背景图片没有填充页面 - 为什么?提前致谢!

这就是我所拥有的:

<style type="text/css">
html, body { 
width:100%;
    height:100%;}

.container {
   width:1000px;
   height:100%;
   background-image:url('background.jpg');
   position: relative;
   margin-left:auto;
   margin-right:auto;
  }
.header {
   width:1000px;
   height:300px;
   background-color:#ffffff;
   position: absolute;
   top:0px;
   left:0px;
  }


.content {
   width: 680px;
   position:absolute;
   top: 350px;
   left: 310px;
  }

.post {
   width: 630px;
   padding: 20px;
   padding-top: 50px;

  }

.title {
   width: 650px;
   height: 20px;
   padding: 10px;
   position: absolute; left: -10px; top: 10px;
  }




</style>

<body>
<div class="container">

 <div class="header">
 Placeholder for header image.
 <p><a href="index.html">Home</a></p>
 </div>


 <div class="content">
  <div class="post">
   <div class="title">Welcome</div>

    <img src="PLACEHOLDER.JPG" alt="Proposal Photo" width="630" />
  </div>
 </div>
</div>

2 个答案:

答案 0 :(得分:1)

试试这个

.container {
  width:1000px;
  height:100%;
  background-image:url('background.jpg') no-repeat;
  position: relative;
  margin-left:auto;
  margin-right:auto;
  background-size:100%
}

答案 1 :(得分:0)

这样做:

body {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

然后您的div可以使用此代码进行缩放:

.container {
    width:100%;
    height:100%;
    position: relative;
}
相关问题