How to overlay image with color in CSS?

前端 未结 11 802
轻奢々
轻奢々 2020-12-14 13:51

Objective

I want a color overlay on this header element. How can I do this with CSS?

Code

HTML

11条回答
  •  抹茶落季
    2020-12-14 14:44

    Use mutple backgorund on the element, and use a linear-gradient as your color overlay by declaring both start and end color-stops as the same value.

    Note that layers in a multi-background declaration are read much like they are rendered, top-to-bottom, so put your overlay first, then your bg image:

    #header {
      background: 
        linear-gradient(to bottom, rgba(100, 100, 0, 0.5), rgba(100, 100, 0, 0.5)) cover,
        url(../img/bg.jpg) 0 0 no-repeat fixed;
      height: 100%;
      overflow: hidden;
      color: #FFFFFF
    }
    

提交回复
热议问题