我使用渐变作为背景,它一直延伸到页面末尾,但是在滚动/溢出后它开始重复。如何在滚动后将渐变拉伸(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-repeat
和background-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/