【发布时间】:2017-11-28 12:16:34
【问题描述】:
如何使用 CSS 使多个图像仅在特定区域相互渐变,如下图所示?
我尝试过的:
.container {
position: relative;
display: flex;
height: 200px;
}
.container:before {
content: '';
position: absolute;
width: 80px;
top: 0;
bottom: 0;
right: 50%;
margin-right: -40px;
background: url(https://www.w3schools.com/w3css/img_fjords.jpg);
filter: blur(5px);
-webkit-filter: blur(5px);
}
.container > div {
flex: 1;
background-size: 100% 100%;
}
<div class="container">
<div style="backgroud-image:url(https://www.w3schools.com/w3css/img_fjords.jpg)"></div>
<div style="background-image:url(https://www.w3schools.com/w3css/img_fjords.jpg)"></div>
</div>
但是,如下图所示,背景图像没有褪色/过渡:
更新
我的问题没有得到任何可靠的答案,但这段代码似乎是迄今为止我能得到的最接近的答案。
<div class="hero-image">
<img src="http://static.peter.coffee/codepen-assets/keyboard-background.jpg" />
</div>
<div class="hero-before">
<img src="http://static.peter.coffee/codepen-assets/keyboard-background.jpg" />
</div>
<style>
img {
/* To contain the image to the confines of the div */
max-width: 100%;
}
.hero-image {
max-width: 100%;
width: 800px;
margin: auto;
}
.hero-before {
max-width: 100%;
width: 800px;
margin: auto;
}
.hero-image::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0, #fff 100%);
margin-top: -50px;
height: 40px;
width: 100%;
content: '';
}
.hero-before::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, #fff 0%, rgba(255, 255, 255, 0) 100%);
margin-top: -345px;
height: 50px;
width: 100%;
content: '';
}
</style>
【问题讨论】:
标签: html css image gradient linear-gradients