CSS样式学习-CSS 背景
老规矩。。。www.java1234.com 初学者最适合去得地方!
背景色
这条规则把元素的背景设置为灰色:
p {background-color: gray;}
如果您希望背景色从元素中的文本向外少有延伸,只需增加一些内边距:
p {background-color: gray; padding: 20px;}
background-color 不能继承,其默认值是 transparent。transparent 有“透明”
背景图像
body {background-image: url(/i/eg_bg_04.gif);}
背景重复
repeat repeat-x 和 repeat-y 分别导致图像只在水平或垂直方向上重 no-repeat body
{
background-image: url(/i/eg_bg_03.gif);
background-repeat: repeat-y;
}
背景定位 关键字:top、bottom、left、right 和 center。
下面的例子在 body 元素中将一个背景图像居中放置:
body
{
background-image:url('/i/eg_bg_03.gif');
background-repeat:no-repeat;
background-position:center;
}
因此,如果你想把一个图像放在水平方向 2/3、垂直方向 1/3 处,可以这样声明:
body
{
background-image:url('/i/eg_bg_03.gif');
background-repeat:no-repeat;
background-position:66% 33%;
}
背景关联
可以通过 background-attachment 属性防止这种滚动。通过这个属性,可以声明图像相对于可视区是固定的(fixed),因此不会受到滚动的影响:
body
{
background-image:url(/i/eg_bg_02.gif);
background-repeat:no-repeat;
background-attachment:fixed
}
background-attachment 属性的默认值是 scroll
我学习JAVA的母校