首页 > 解决方案 > 将渐变亮度滤镜应用于图像

问题描述

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>&nbsp</a><a>4th June</a>
            </div>
            <div class="ml-auto">
                <a>3421</a><a>&nbsp</a><i class="fa fa-user-friends fa-fw"></i>
            </div>
        </div>
    </div>
</div>


  [1]: https://i.ibb.co/TTTdrDP/card-image.jpg

标签: htmltwitter-bootstrap

解决方案


你的意思是这样的吗?

.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>&nbsp;</a><a>4th June</a>
            </div>
            <div class="ml-auto">
                <a>3421</a><a>&nbsp;</a><i class="fa fa-user-friends fa-fw"></i>
            </div>
        </div>
    </div>
</div>


推荐阅读