CSS背景固定上方不动

html-css032

CSS背景固定上方不动,第1张

这样子来写:

body{

background:color url(路径) top left repeat-x

}

里边依次表示背景颜色 背景图片 图片位于左上 图片横向平铺

刚好适合渐变颜色的~

你需要用到background-position这个属性,用以规定背景图片的位置。让图片居中偏下的代码为:

background-positon:center bottom 或 background-positon:bottom

全部的位置代码如下:

background-position: left 代表背景图横向(X轴)靠左,纵向(Y轴)居中。(9点钟位置)

background-position: right 代表背景图横向(X轴)靠右,纵向(Y轴)居中。(3点钟位置)

background-position: top 代表背景图横向(X轴)居中,纵向(Y轴)靠上。(12点钟位置)

background-position: bottom 代表背景图横向(X轴)居中,纵向(Y轴)靠下。(6点钟位置)

background-position: center 代表背景图横向(X轴)居中,纵向(Y轴)居中。(绝对居中)

background-position: left top 代表背景图横向(X轴)靠左,纵向(Y轴)靠上。(10点钟位置)

background-position: left bottom 代表背景图横向(X轴)靠左,纵向(Y轴)靠下。(7点钟位置)

background-position: right top 代表背景图横向(X轴)靠右,纵向(Y轴)靠上。(1点钟位置)

background-position: right bottom 代表背景图横向(X轴)靠右,纵向(Y轴)靠下。(5点钟位置)

background:url(图片地址) repeat-x或no-repeat bottom这样就是背景图片从底部开始显示,设置repeat-x是让在横向循环,不要设置repeat-y,这个是纵向循环,上边的部分,超出图片高度就不会显示了。不够图片的高度就会把图片的上部分隐藏