嵌套div的整页响应背景

时间:2018-02-10 05:04:41

标签: css html5

我在几个div(嵌套在$(tail -12 really_large.txt | wc -c)中)制作了一个由CSS剪辑组成的BG,如何配置整个响应的东西?当我将宽度或高度设置为100%时,背景根本不会渲染。

.background
body,
html {
  margin: 0px;
}

.bg0 {
  position: relative;
  width: 1366px;
  height: 675px;
  background-color: #3B3B3B;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.bg1 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #333333;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
  clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
}

.bg2 {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background-color: #2D2D2D;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-clip-path: polygon(0 12%, 0 86%, 35% 50%);
  clip-path: polygon(0 12%, 0 86%, 35% 50%);
}

#wrapper {
  position: relative;
  width: 200px;
  height: 200px;
}

.content {
  position: relative;
}

.background {
  position: absolute;
}

1 个答案:

答案 0 :(得分:0)

首先....为什么你使用固定宽度到bg0类,并且你给它的bg0类更大的宽度比它的父元素#wrapper ...

我认为不需要......只需设置width班级的height.background

Stack Snippet



body,
html {
  margin: 0px;
}

.bg0 {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #3B3B3B;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.bg1 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #333333;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
  clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
}

.bg2 {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background-color: #2D2D2D;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-clip-path: polygon(0 12%, 0 86%, 35% 50%);
  clip-path: polygon(0 12%, 0 86%, 35% 50%);
}

#wrapper {
  position: relative;
  width: 200px;
  height: 200px;
}

.content {
  position: relative;
}

.background {
  position: absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
}

<div id="wrapper">
  <div class="background">
    <div class="bg0"></div>
    <div class="bg1"></div>
    <div class="bg2"></div>
  </div>
  <div class="content">
    <h1>Content!!</h1>
  </div>
</div>
&#13;
&#13;
&#13;