1

我想让我网站上的背景变成渐变色。这是因为我刚刚开始制作网站,我只想了解 CSS 是如何工作的,什么不是。

这是我的代码:

background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* FF3.6+ */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 0.65))); /* Chrome,Safari4+ */
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, .8) 0%, rgba(0, 0, 0, 0.65) 100%); /* Chrome10+,Safari5.1+ */
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* Opera 11.10+ */
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* IE10+ */
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#a6000000',GradientType=0 ); /* IE6-9 */

我不希望渐变停止然后从白色重复。我希望渐变根据当前媒体的大小而变化。

4

2 回答 2

2

将htmlheightwidthbody 的 and 设置为 100%,这些选项用于背景:

background-repeat: no-repeat;
background-attachment: fixed;

演示

如果你不这样做,当你滚动超过浏览器的高度时,渐变会重复。

于 2012-11-25T03:46:00.200 回答
0

这是您需要做的,将 height:100% 应用于 html 和 body。如果您的网站将在移动设备上,您需要添加

background-attachment:也固定在身体上。

  html{
 height: 100%;
 }
 body{
 height: 100%;
 background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0) 100%, rgba(0, 0, 0, 0.65) 100%); /* FF3.6+ */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(100%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 0.65))); /* Chrome,Safari4+ */
 background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, .8) 0%, rgba(0, 0, 0, 0.65) 100%); /* Chrome10+,Safari5.1+ */
  background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0) 100%, rgba(0, 0, 0, 0.65) 100%); /* Opera 11.10+ */
 background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0) 100%, rgba(0, 0, 0, 0.65) 100%); /* IE10+ */
 background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* W3C */
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#a6000000',GradientType=0 ); /* IE6-9 */}
于 2012-11-25T03:43:12.310 回答