Darken background image on hover

后端 未结 14 1365
囚心锁ツ
囚心锁ツ 2020-12-22 23:03

How would I darken a background image on hover without making a new darker image?

CSS:

.image {
  background: url(\         


        
相关标签:
14条回答
  • 2020-12-22 23:27

    You can use opacity:

    .image {
        background: url('http://cdn1.iconfinder.com/data/icons/round-simple-social-icons/58/facebook.png');
        width: 58px;
        height: 58px;
        opacity:0.5;
    }
    
    .image:hover{
        opacity:1;
    }
    

    JSFiddle

    0 讨论(0)
  • 2020-12-22 23:30

    Similar, but again a little bit different.

    Make the image 100% opacity so it is clear. And then on img hover reduce it to the opacity you want. In this example, I have also added easing for a nice transition.

    img {
        -webkit-filter: brightness(100%);
    }
    
    img:hover {
        -webkit-filter: brightness(70%);
        -webkit-transition: all 1s ease;
        -moz-transition: all 1s ease;
        -o-transition: all 1s ease;
        -ms-transition: all 1s ease;
        transition: all 1s ease;
    }
    

    That will do it, Hope that helps.

    Thank you Robert Byers for your jsfiddle

    0 讨论(0)
提交回复
热议问题