Can I apply multiple background colors with CSS3?

后端 未结 6 2073
死守一世寂寞
死守一世寂寞 2020-11-27 06:13

I know how to specify multiple background images using CSS3 and modify how they are displayed using different options.

Currently I have a

, w
6条回答
  •  孤街浪徒
    2020-11-27 07:10

    You can use as many colors and images as you desire.

    Please note that the priority with which the background images are rendered is FILO, the first specified image is on the top layer, the last specified image is on the bottom layer (see the snippet).

    #composition {
        width: 400px;
        height: 200px;
        background-image:
            linear-gradient(to right, #FF0000, #FF0000), /* gradient 1 as solid color */
            linear-gradient(to right, #00FF00, #00FF00), /* gradient 2 as solid color */
            linear-gradient(to right, #0000FF, #0000FF), /* gradient 3 as solid color */
            url('http://lorempixel.com/400/200/'); /* image */
        background-repeat: no-repeat; /* same as no-repeat, no-repeat, no-repeat */
        background-position:
            0 0, /* gradient 1 */
            20px 0, /* gradient 2 */
            40px 0, /* gradient 3 */
            0 0; /* image position */
        background-size:
            30px 30px,
            30px 30px,
            30px 30px,
            100% 100%;
    }

提交回复
热议问题