我有一个背景图片,我想在上面添加两个渐变滤镜... 第一个滤镜是从右到左的蓝色滤镜,可以,但是第二个滤镜是从上到下的黑色滤镜,这一点都不平滑。 我希望我的代码生成此: 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>
答案 0 :(得分: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>
答案 1 :(得分: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进行了更改。我希望它能解决您的问题。
答案 2 :(得分: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>