本篇文章将简单介绍背景的用法。
目录
背景颜色:
background-color:颜色值;
background-image:url(图片地址);//none;为默认值
背景平铺 :
background-repeat:repeat; //图片在纵向、横向上都平铺
background-repeat:no-repeat; //图片不平铺
background-repeat:repeat-x; //图片在横向平铺
background-repeat:repeat-y; //图片在纵向平铺
(注意:背景其实可以同时加颜色背景和图片背景,只不过图片会压住颜色。)
背景图片位置
background-position:x y;
参数代表:x坐标和y坐标,可以使用方位名词或精确单位。
方位名词position:center、left、right、top、bottom
精确坐标length:百分数50%;或者50px则y默认为center;或者x,y坐标20px 50px;
background-position:50%;
background-position:50px;
background-position:20px 50px;
背景半透明
background:rgba(0,0,0,0.3);
rgb:代表颜色
a:代表透明度,从0到1,0全透明,1不透明。
背景图像的固定(背景附着)
background-attachment:scroll | fixed ;
scroll:背景图像时随着对象内容滚动。
fixed:背景图像的固定。
复合写法
写背景属性时无特定的书写顺序,一般顺序为
background:背景颜色,背景图片地址,平铺,图像滚动,背景图片位置;
(新手小白,如有错误欢迎指正!)