html - CSS 背景渐变在溢出时重复

标签 html css

我使用渐变作为背景,它一直延伸到页面末尾,但是在滚动/溢出后它开始重复。如何在滚动后将渐变拉伸(stretch)到页面底部?

    html
{
    height:100%;
    width:100%;
}

body
{
    margin:0;
    padding:0;
    width:100%;
    height:100%;
    min-height:100%;
    background-repeat:no-repeat;
    background-attachment: fixed;

background: rgb(242,245,246); /* Old browsers */
background: -moz-linear-gradient(top,  rgba(242,245,246,1) 0%, rgba(227,234,237,1) 37%, rgba(200,215,220,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(242,245,246,1)), color-stop(37%,rgba(227,234,237,1)), color-stop(100%,rgba(200,215,220,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2f5f6', endColorstr='#c8d7dc',GradientType=0 ); /* IE6-9 */

}

最佳答案

您似乎错误地订购了一些 CSS 属性。看看这个部分。

background-repeat:no-repeat;
background-attachment: fixed;
background: rgb(242,245,246); /* Old browsers */

您在简写background 属性之前指定了简写属性background-repeatbackground-attachment。当读取 background 属性时,它将重置所有先前设置的背景属性。

只需将它们移到您的其他背景属性下方,它就会起作用。

html
{
    height:100%;
    width:100%;
}

body
{
    margin:0;
    padding:0;
    width:100%;
    height:100%;
    min-height:100%;
    background: rgb(242,245,246); /* Old browsers */
    background: -moz-linear-gradient(top,  rgba(242,245,246,1) 0%, rgba(227,234,237,1) 37%, rgba(200,215,220,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(242,245,246,1)), color-stop(37%,rgba(227,234,237,1)), color-stop(100%,rgba(200,215,220,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom,  rgba(242,245,246,1) 0%,rgba(227,234,237,1) 37%,rgba(200,215,220,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2f5f6', endColorstr='#c8d7dc',GradientType=0 ); /* IE6-9 */
    background-repeat:no-repeat;
    background-attachment: fixed;
}
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>
<h1>blah</h1>

关于html - CSS 背景渐变在溢出时重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28667411/

相关文章:

html - 是否可以仅在背景上使用类似 iOS7 的模糊效果?

javascript - jquery slider 返回不一致的值

html - CSS:删除行中的最后一个元素

ios - 删除 iphone 中的 "choose from gallary"选项?

html - 响应式 Twitter Bootstrap : <body> and navbar right padding/margin appears when width is < 767/768px

javascript - 第二次单击按钮时切换反向动画

css - 将 div 与同一类水平对齐

javascript - 当屏幕调整为较小的屏幕时,如何自动调整按钮的大小?

html - 防止 HTML 元素在较小的屏幕上相互重叠

css - 使位于图像上的 Div 具有响应性?