CSS - 覆盖图像上的渐变?

lau*_*kok 4 html css cover background-image

如何在封面图像上设置渐变图层?

例如:

header {
  position: relative;
  height: 300px;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-image: url('http://www.planwallpaper.com/static/images/Free-Wallpaper-Nature-Scenes.jpg');
  background-size: cover;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
}

h1 {
  margin: 0;
  padding: 100px 0;
  font: 44px "Arial";
  text-align: center;
}

header h1 {
  color: white;
}
Run Code Online (Sandbox Code Playgroud)
<header>
  <h1>Header Content</h1>
</header>

<section>
  <h1>Section Content</h1>
</section>
Run Code Online (Sandbox Code Playgroud)

我希望这个渐变覆盖该图像:

background-image: linear-gradient(to bottom right, #002f4b, #dc4225);
Run Code Online (Sandbox Code Playgroud)

可能吗?

Gus*_*nér 6

您可以定义多个背景,然后设置background-blend-modemultiply.像这样的东西

header {
  position: relative;
  height: 300px;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: cover;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
  background-blend-mode: multiply;
  background: linear-gradient(to bottom right, #002f4b, #dc4225), url('http://www.planwallpaper.com/static/images/Free-Wallpaper-Nature-Scenes.jpg');
  background-size: cover;
}

h1 {
  margin: 0;
  padding: 100px 0;
  font: 44px "Arial";
  text-align: center;
}

header h1 {
  color: white;
}
Run Code Online (Sandbox Code Playgroud)
<header>
  <h1>Header Content</h1>
</header>

<section>
  <h1>Section Content</h1>
</section>
Run Code Online (Sandbox Code Playgroud)


Ger*_*ard 6

使用rgba的透明度和双background-image

header {
  position: relative;
  height: 300px;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-image: linear-gradient(to bottom right, rgba(0, 47, 75, .5), rgba(220, 66, 37, .5)), url('http://www.planwallpaper.com/static/images/Free-Wallpaper-Nature-Scenes.jpg');
  background-size: cover;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
}
h1 {
  margin: 0;
  padding: 100px 0;
  font: 44px "Arial";
  text-align: center;
}

header h1 {
  color: white;
}
Run Code Online (Sandbox Code Playgroud)
<header>
  <h1>Header Content</h1>
</header>

<section>
  <h1>Section Content</h1>
</section>
Run Code Online (Sandbox Code Playgroud)