我在引导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
答案 0 :(得分:0)
您的意思是这样的吗?
.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>