CSS - gradient over a cover image?

laukok picture laukok · Jul 1, 2017 · Viewed 7.6k times · Source

How can I have a gradient layer over a cover image?

For instance:

I want this gradient over that image:

background-image: linear-gradient(to bottom right, #002f4b, #dc4225);

Is it possible?

Answer

Gustaf Gunér picture Gustaf Gunér · Jul 1, 2017

You can define multiple backgrounds and then set background-blend-mode to multiply. Something like this

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;
}
<header>
  <h1>Header Content</h1>
</header>

<section>
  <h1>Section Content</h1>
</section>