CSS3 线性渐变 100% 高度不固定

标签 css background height

我有 html:

<!doctype html>
    <html>
    <head>
        <title>test</title>
        <meta charset="utf-8"/>
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <meta name="viewport" content="width=device-width"/>
        <meta name="format-detection" content="telephone=no"/>
        <!--[if lt IE 9]>
            <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    </head>
    <body>
    <section class="container">
        //full html on jsfiddle
    </section>
    </body>
    </html>

我有 CSS

html, body {height:100%;margin:0;}
body {
    background-color:#f4cbc9;
    background-image: linear-gradient(top, rgb(171,153,180) 0%, rgb(244,203,201) 50%, rgb(247,231,208) 100%);
    background-image: -o-linear-gradient(top, rgb(171,153,180) 0%, rgb(244,203,201) 50%, rgb(247,231,208) 100%);
    background-image: -moz-linear-gradient(top, rgb(171,153,180) 0%, rgb(244,203,201) 50%, rgb(247,231,208) 100%);
    background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(171,153,180)),color-stop(0.50, rgb(244,203,201)),color-stop(1, rgb(247,231,208)));
    background-image: -webkit-linear-gradient(top, rgb(171,153,180) 0%, rgb(244,203,201) 50%, rgb(247,231,208) 100%);
    background-image: -ms-linear-gradient(top, rgb(171,153,180) 0%, rgb(244,203,201) 50%, rgb(247,231,208) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ab99b4', endColorstr='#f4cbc9');
}

我需要整个 body 高度的背景(线性渐变)。不固定,不重复。

参见 JsFiddle

最佳答案

使用 min-height 代替 height

http://jsfiddle.net/CYrpd/6/

这将使 bg 拉伸(stretch)到 body 的全尺寸,但绝不会小于窗口显示的尺寸。

关于CSS3 线性渐变 100% 高度不固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13057274/

相关文章:

javascript - 在页面加载时触发 Javascript 文本和图片预览

javascript - angular-Js 中的刷新页面请求

javascript - 当值为空时,我的输入不想将其自身着色为红色

Android FullScreen 主题降低显示按钮的高度

切换到焦点时,CSS 从零开始增加高度

javascript - 寻找一种功能,使我能够将特定的导航菜单拖动到屏幕上的任何位置

javascript - 强制 div 高度为最接近背景图像高度的倍数

colors - 如何更改 Electron 浏览器窗口的背景颜色(例如通过单击按钮)?

Android:具有两种背景颜色的按钮

javascript - Facebook Like 按钮 - 防止 XFBML 版本调整高度