使用@media设置填充区域

时间:2017-05-26 13:33:50

标签: html css

对于我正在使用的WP

@media (min-width: 768px) {
  section {
    padding: 50px 0;
  }
}

用于几个部分之间的自动填充。现在,对于一个部分,我想在它前面添加一个背景图像和一个灰色透明框:

section {
  padding: 100px 0; #which does not do anything, can change it to random values. 
}
section .background1 {
  background-color: #222222;
  background-image: url('../img/bg.jpg');
  background-repeat: no-repeat;
  background-attachment: scroll;
  background-position: center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
}
section .bg-layer {
    background-color: rgba(50,50,50, 0.6);
    top: 0 ;
    left: 0;
    width: 100%;
    height: 100%;
}

我的html代码看起来如下,里面有一些文字等等:

<section>
  <div class="background1">
    <div class="bg-layer">
      <div class="container">

这原则上工作得很好,但填充区域没有填充背景图像,我无法做到这一点。所以我基本上希望图像和灰色区域朝向这一部分的一般填充区域延伸。任何人都可以帮助或描述最好的解决方法吗?好多了!

1 个答案:

答案 0 :(得分:0)

我想这就是你想要达到的目标。

section {
  padding: 100px 0;
  background-color: #dddddd;
}
section h2.section-heading {
  text-transform: none;
  font-size: 40px;
  margin-top: 10px;
  margin-bottom: 15px;
}
section h3.section-subheading {
  font-size: 16px;
  font-family: "Droid Serif", "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-transform: none;
  font-style: italic;
  font-weight: 400;
  margin-bottom: 75px;
}
section .background1 {
  background-color: #ffffff;
  background-image: url('../img/bg.jpg');
  background-repeat: no-repeat;
  background-attachment: scroll;
  background-position: center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
}
section .bg-layer {
    background-color: rgba(50,50,50, 0.6);
    padding: 50px 0;
}
section h2.bg-section-heading { 
  color: white;
  text-transform: none;
  font-size: 40px;
  margin-top: 10px;
  margin-bottom: 15px;
}
section h3.bg-section-subheading {
  color: white;
  font-size: 16px;
  font-family: "Droid Serif", "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-transform: none;
  font-style: italic;
  font-weight: 400;
}

@media (min-width: 768px) {
  section {
    padding: 50px 0;
  }
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Montserrat", "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-transform: uppercase;
  font-weight: 700;
}
.bg-darkest-gray {
  background-color: #222222;
  padding: 0;
  }

Fiddle