在图像上添加平滑渐变滤镜

问题描述 投票:-1回答:3

我有一个背景图像,我想在它上面添加两个渐变滤镜...第一个滤镜是从右到左的蓝色滤镜,这是好的,但第二个滤镜是从上到下的黑色滤镜,它根本不光滑。我希望我的代码生成这个:https://dribbble.com/shots/2595241-VOID-Conference/attachments/516900但我的黑色过滤器毁了它。

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

html,
body {
  height: 100%;
}

.landing {
  width: 100vw;
  height: 100vh;
  position: relative;
}

.landing .bg {
  width: 100%;
  height: 100%;
  position: absolute;
  background: url('https://images.unsplash.com/photo-1448574271786-c15eea67e169?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&dl=sebastian-unrau-48222-unsplash.jpg') center top no-repeat;
  background-size: 100% 75%;
}

.landing .bg::before {
  content: '';
  width: 100%;
  height: 75%;
  position: absolute;
  background-image: linear-gradient(to right, rgb(0, 50, 150) 0%, rgb(0, 25, 50) 100%);
  opacity: .2;
}

.landing .bg::after {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  background-image: linear-gradient(to bottom, transparent 40%, rgb(20, 20, 20) 60%);
}
<div class="landing">
  <div class="bg"></div>
</div>
html css image gradient
3个回答
0
投票

添加不透明度并将背景的高度从下到上设置,与从左到右相同

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

html,
body {
  height: 100%;
}

.landing {
  width: 100vw;
  height: 100vh;
  position: relative;
}

.landing .bg {
  width: 100%;
  height: 100%;
  position: absolute;
  background: url('https://images.unsplash.com/photo-1448574271786-c15eea67e169?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&dl=sebastian-unrau-48222-unsplash.jpg') center top no-repeat;
  background-size: 100% 75%;
}

.landing .bg::before {
  content: '';
  width: 100%;
  height: 75%;
  position: absolute;
  background-image: linear-gradient(to right, rgb(0, 50, 150) 0%, rgb(0, 25, 50) 100%);
  opacity: .2;
}

.landing .bg::after {
  content: '';
  width: 100%;
  height: 75%;
  position: absolute;
  background-image: linear-gradient(to bottom, transparent 40%, rgb(20, 20, 20) 60%);
  opacity: 0.6;
}
<div class="landing">
  <div class="bg"></div>
</div>

0
投票

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      box-sizing: border-box;
      padding: 0;
      margin: 0;
    }
    
    html,
    body {
      height: 100%;
    }
    
    .landing {
      width: 100vw;
      height: 100vh;
      position: relative;
    }
    
    .landing .bg {
      width: 100%;
      height: 100%;
      position: absolute;
      background: url('https://images.unsplash.com/photo-1448574271786-c15eea67e169?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&dl=sebastian-unrau-48222-unsplash.jpg') center top no-repeat;
      background-size: 100% 100%;
    }
    
    .landing .bg::before {
      content: '';
      width: 100%;
      height: 100%;
      position: absolute;
      background-image: linear-gradient(to right, rgb(0, 50, 150) 0%, rgb(0, 25, 50) 100%);
      opacity: .2;
    }
    
    .landing .bg::after {
      content: '';
      width: 100%;
      height: 100%;
      position: absolute;
      background-image: linear-gradient(to bottom, transparent 40%, rgb(20, 20, 20) 60%);
      opacity: 0.2
    }
  </style>
</head>

<body>
  <div class="landing">
    <div class="bg"></div>
  </div>
</body>

</html>

我在CSS中进行了更改。我希望它能解决你的问题。


0
投票

您可以使用多个背景简化代码:

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

html,
body {
  height: 100%;
}

.landing {
  height: 100vh;
  background: 
    linear-gradient(to bottom, transparent 40%, rgba(20, 20, 20,0.8) 80%),
    linear-gradient(to right, rgba(0, 50, 150, 0.2) 0%, rgba(0, 25, 50, 0.2) 100%),
    url('https://images.unsplash.com/photo-1448574271786-c15eea67e169?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&dl=sebastian-unrau-48222-unsplash.jpg') top;
  background-size: 100% 75%;
  background-repeat:no-repeat;
}
<div class="landing">
</div>
© www.soinside.com 2019 - 2024. All rights reserved.