无法在位置绝对div上添加背景图像

时间:2015-07-13 21:19:29

标签: css css3

请你看一下this demo并告诉我为什么我无法将图片添加到#img-box

              
html, body {
    height:100%;
    width:100%;
}
#wrapper {
    position: relative;
    height: 100%;
    width: 100%;
}
#img-box {
    position: absolute;
    background-image: url("http://www.bluearthrenewables.com/wp-content/uploads/2014/12/7_Intake-Construction_CullitonCreek.jpg");
    top:0;
    left:0;
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

2 个答案:

答案 0 :(得分:1)

因为ExecuteScalar()没有任何宽度&与之相关的高度。尝试定义

#img-box
html, body {
    height:100%;
    width:100%;
}
#wrapper {
    position: relative;
    height: 100%;
    width: 100%;
}
#img-box {
    position: absolute;
    background-image: url("http://www.clker.com/cliparts/2/0/f/b/13873752061098664878happy_smiley-th.png");
    height: 100%;
    width: 100%;
    top:0;
    left:0;
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

答案 1 :(得分:0)

使用right:0bottom:0

提供div维度

html,
body {
  height: 100%;
  width: 100%;
}
#wrapper {
  position: relative;
  height: 100%;
  width: 100%;
}
#img-box {
  position: absolute;
  background-image: url("http://www.bluearthrenewables.com/wp-content/uploads/2014/12/7_Intake-Construction_CullitonCreek.jpg");
  top: 0;
  bottom: 0;
  left: 0;
  right:0;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
<div id="wrapper">
  <div id="img-box"></div>
  <div id="tets"></div>
  <div id="tes3"></div>
</div>