CSS: Semi-transparent background and an image

后端 未结 3 2073
无人及你
无人及你 2021-01-03 04:20
body {
  background-image: url(\'cloud.png\');
  background-color: rgba(255, 255, 255, 0.6);
}

I tried using the above to produce a semi-transparen

3条回答
  •  悲&欢浪女
    2021-01-03 04:46

    You can use the css "before" pseudo class to create the white overlay and place before all the content in your DOM. Add z-index:-1 to ensure it doesn't sit on top of other elements:

    body {
        background: url("image.jpg");
    }
    body:before {
        content: "";
        display: block;
        position: fixed;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        z-index: -1;
        background-color: rgba(255, 255, 255, 0.6);
    }
    

    jsfiddle

提交回复
热议问题