有没有一种方法可以使用从屏幕中心/中间开始的线性渐变背景?
这是我的当前css:
body {
display: table;
width: 100%;
height: 100%;
margin: 0 auto;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center top;
background-size: 800px;
background: blue;
background: -webkit-linear-gradient(to left, black, blue, blue, black 800px);
background: linear-gradient(to left, black, blue, blue, black 800px);
}
渐变背景在800像素后停止(是我想要的),但它出现在页面内容的右侧,而不是其后面。我无法将它移动到其他任何位置。而且根据窗口大小不同,它与内容之间的距离也会有所不同。我需要它固定在中心,在我的内容后面。也许下一行类似于此内容?
background: linear-gradient(to sides, blue, black 400px);
所以我需要能够设置线性渐变的起始位置为中心,让浏览器将其向两侧运行。距离中心400像素是它应该停止的位置(在此之后使用最后一种颜色) - 因此渐变应该有800像素宽度。
margin:0
。但是我写错了,实际上背景在原始屏幕高度的100%后面没有出现。需要修改你最后一行的代码:background-repeat: repeat-y;
,现在它正常工作了! - JaSon