【问题标题】:How to have a gradient background on a page that covers the entire page without the "window-blind effect"?如何在没有“窗口盲效果”的情况下在覆盖整个页面的页面上具有渐变背景?
【发布时间】:2013-07-15 22:00:51
【问题描述】:

我希望我的页面具有渐变色,从左侧的深色变为中间的亮色,然后在右侧边缘变回深色。我看过一些创建渐变的示例,但我不知道在 CSS 中的哪个位置设置了图案的大小,而且图案重复太快,不符合我的口味。

例如,这里有一些 CSS:

html {
   background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#2F2727), to(#1a82f7));
   background-image: -webkit-linear-gradient(top, #2F2727, #1a82f7); 
   background-image:    -moz-linear-gradient(top, #2F2727, #1a82f7);
   background-image:     -ms-linear-gradient(top, #2F2727, #1a82f7);
   background-image:      -o-linear-gradient(top, #2F2727, #1a82f7);
}

...我在这里找到的:http://css-tricks.com/css3-gradients/

这是一个你可以运行的 jsfiddle:

http://jsfiddle.net/clayshannon/VLXbu/

它不能是一个固定的尺寸,因为差异是屏幕尺寸,特别是在手机和台式机之间。有没有办法使用 %s 的屏幕宽度来实现这一点?

【问题讨论】:

  • html元素的高度设置为100%
  • 没错。说明: html 仅与其内容一样高,即 100px 高的部分。 @onetrickpony,你为什么不把这个作为答案发布?
  • @ClayShannon 你真的应该以通用(没有前缀)linear-gradient 结尾。这样,它将保持更新的时间更长。
  • 用你的 cmets 更新了它。 jsfiddle.net/clayshannon/VLXbu/2如果您添加答案,我将标记为答案。

标签: background gradient background-color css


【解决方案1】:

试试

html {
background: #2f2727; /* Old browsers */
background: -moz-linear-gradient(top, #2f2727 0%, #1a82f7 49%, #1a82f7 49%, #2f2727 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2f2727), color-stop(49%,#1a82f7), color-stop(49%,#1a82f7), color-stop(100%,#2f2727)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #2f2727 0%,#1a82f7 49%,#1a82f7 49%,#2f2727 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #2f2727 0%,#1a82f7 49%,#1a82f7 49%,#2f2727 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #2f2727 0%,#1a82f7 49%,#1a82f7 49%,#2f2727 100%); /* IE10+ */
background: linear-gradient(to bottom, #2f2727 0%,#1a82f7 49%,#1a82f7 49%,#2f2727 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2f2727', endColorstr='#2f2727',GradientType=0 ); /* IE6-9 */
min-height: 100%; height: auto !important; height: 100%;

}

http://jsfiddle.net/pepean/hSjdg/2/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2016-09-26
    • 2016-09-28
    • 2022-07-20
    • 1970-01-01
    相关资源
    最近更新 更多