html - 将渐变亮度滤镜应用于图像
问题描述
card
我在引导类中显示了一系列照片。图片上面需要有白色文字,所以我在照片上添加了一个深色滤镜,filter: brightness(60%);
这样文字就可以清楚地阅读。
查看图像当前的外观https://i.ibb.co/TTTdrDP/card-image.jpg
白色文字仅位于照片的底部,因此我只想将其应用于filter: brightness(60%);
图像的底部并淡入正常亮度。
我尝试了多种形式的渐变,但所做的只是在照片上应用硬色(完全删除照片),而不是在图像顶部使用透明(渐变)滤镜?
我的 CSS
<style>
.card {
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 100%;
}
.card:hover {
box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.2);
}
/* Card image dark filter */
.card-img-top {
width: 100%;
height: 220px;
object-fit: cover;
filter: brightness(60%);
}
/* Align heading text to bottom of photo */
.bottom {
position: absolute;
right: 0;
left: 0;
padding: 10px;
bottom: 0px;
padding-bottom: 40px;
}
.card-footer {
font-size: 12px;
font-weight: normal;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: grey;
background-color: #eeeeee !important;
}
</style>
形象卡
<div class="card" style="width:100%;">
<img class="card-img-top" src="PHOTO HERE" alt="Card image">
<div class="card-img-overlay">
<div class="bottom text-light">
<h2>Hiking in Eastbourne for all who want to join.</h2>
</div>
<a href="example_group" class="stretched-link"></a>
</div>
<div class="card-footer p-2">
<div class="d-flex">
<div>
<i class="fa fa-calendar-alt fa-fw"></i><a> </a><a>4th June</a>
</div>
<div class="ml-auto">
<a>3421</a><a> </a><i class="fa fa-user-friends fa-fw"></i>
</div>
</div>
</div>
</div>
[1]: https://i.ibb.co/TTTdrDP/card-image.jpg
解决方案
你的意思是这样的吗?
.card {
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 100%;
}
.card:hover {
box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.2);
}
/* Card image dark filter */
.card-img-top {
width: 100%;
height: 220px;
object-fit: cover;
filter: brightness(100%);
}
/* Align heading text to bottom of photo */
.bottom {
position: absolute;
right: 0;
left: 0;
bottom: 35px;
padding-top: 90px;
padding-left: 10px;
padding-right: 10px;
height: 150px;
background: linear-gradient(to top, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
}
.card-footer {
font-size: 12px;
font-weight: normal;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: grey;
background-color: #eeeeee !important;
/*filter: brightness(100%); */
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="card" style="width:100%;">
<img class="card-img-top" src="https://media-cdn.tripadvisor.com/media/photo-s/0f/3d/89/4d/foto-com-dome.jpg" alt="Card image">
<div class="card-img-overlay">
<div class="bottom text-light">
<h2>Hiking in Eastbourne for all who want to join.</h2>
</div>
<a href="example_group" class="stretched-link"></a>
</div>
<div class="card-footer p-2">
<div class="d-flex">
<div>
<i class="fa fa-calendar-alt fa-fw"></i><a> </a><a>4th June</a>
</div>
<div class="ml-auto">
<a>3421</a><a> </a><i class="fa fa-user-friends fa-fw"></i>
</div>
</div>
</div>
</div>
推荐阅读
- sql - 如何按集群在 1 个查询中创建(多个)排名?
- amazon-web-services - 如何使用我的 EC2 弹性 IP 地址作为代理服务器?
- python - 序列分类器不适用于长句子
- ibm-midrange - 提示来自程序的 cl 命令
- javascript - jQuery Ajax 调用异常限制后续 ajax 调用
- wordpress - 联系表格 7 在字段错误修复后提交不起作用
- python - 以大于 Python 列表中的值的最小差异对大多数数字进行采样的最快方法
- matlab - 警告:此位置的表格数据不可编辑
- css - 以条纹虚线为背景
- export-to-csv - 在使用 azure 数据工厂提取为 .csv 文件时,是否有任何选项可以将包含逗号的单元格值括在双引号中?