的body
大小与内容,并作为wrapper
,唯一的直接孩子,定位绝对的,它的高度变得0
,但html
是全视
Fiddle
html {
background: #457fca; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left, #457fca, #5691c8); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, #457fca, #5691c8); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, #457fca, #5691c8); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #457fca, #5691c8); /* Standard syntax */
margin: 0;
}
如果你给body
的高度,height: 100vh;
,它的工作以及
Fiddle
body {
height: 100vh;
background: #457fca; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left, #457fca, #5691c8); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, #457fca, #5691c8); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, #457fca, #5691c8); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #457fca, #5691c8); /* Standard syntax */
margin: 0;
}
而且由于wrapper
具有视口的大小,你当然可以设置背景就可以了
Fiddle
#wrapper {
position: absolute;
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
background: #457fca; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left, #457fca, #5691c8); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, #457fca, #5691c8); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, #457fca, #5691c8); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #457fca, #5691c8); /* Standard syntax */
}
我现在有一个bac kground,但是它是单一的颜色。我已经更新了我的小提琴,所以你可以自己看到结果。感谢您的回答! – ItsKasper
@ItsKasper链接到您更新的小提琴? ...和渐变的作品,我改变了一种颜色,所以它清楚地显示:https://jsfiddle.net/cnpczafL/6/ – LGSon
好吧,它确实工作。显然,颜色不够明显。它现在有效。谢谢! – ItsKasper