-webkit-linear-gradient causes banding in Chrome/Safari

前端 未结 6 1779
别跟我提以往
别跟我提以往 2021-01-01 12:44

The title prettymuch says it all. The first picture below is a screenshot when the whole page is about 8000 pixels tall, taken in the latest version of Chrome:

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 13:16

    Looks like a webkit bug. I came up with the work-around below, tested on the latest Chrome and FF. In short, you'll position a div containing the background behind your main content. I also added a few styles to make IE happier.

    Given this HTML:

    
    
        
    
    
        
    bgdiv
    Leave a Comment!
    Your Comment.

    Combined with this stylesheet:

        body{
            background-color: #f3ffff;
            min-height: 100%;
            margin:0px;
        }
        .background {
            height: 250px;
            left: 0;
            position: absolute;  /* could use fixed if you like. */
            right: 0;
            top: 0;
            z-index: -10;
    
            background-image:
                -webkit-linear-gradient(top,
                    rgba(99, 173, 241, 1) 0px,
                    rgba(0, 255, 255, 0) 250px
                );
            background-image:
                -moz-linear-gradient(top,
                    rgba(99, 173, 241, 1) 0px,
                    rgba(0, 255, 255, 0) 250px
                );
            background-image:
                -o-linear-gradient(top,
                    rgba(99, 173, 241, 1) 0px,
                    rgba(0, 255, 255, 0) 250px
                );
            background-image:
                -ms-linear-gradient(top,
                    rgba(99,173,241,1) 0%,
                    rgba(0,255,255,0) 250px
                ); /* IE10+ */
            filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#63adf1', endColorstr='#0000ffff',GradientType=0 ); /* IE6-9 */
            background-image:
                linear-gradient(top,
                    rgba(99,173,241,1) 0%,
                    rgba(0,255,255,0) 250px
                ); /* W3C */
            background-position: center top, center top;
            background-repeat: no-repeat, repeat-x;
        }
        .content_pane {
            background: white;
            border: 1px dotted white;
            border: 1px solid grey;
            font-family: arial, sans;
            font-weight: bold;
            margin: 6em auto 5em;
            width: 50%;
        }
        .titlebar {
            background: #3f7cdb;
            color: white;
            font-family: arial, sans;
            padding: .25em 2ex .25em;
        }
        .comment {
            padding: 1em;
        }
    

    It should come out looking like this, regardless of window size:

    Chrome image

提交回复
热议问题