的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