求解html背景图片和背景颜色同时存在的代码。。给个模版形式谢谢

如题所述

一般有两种写法,第一种是分开写的,比如:

body{
    background-image:url('这里是图片路径'); /*加载图片*/
    background-color:#fff; /*设置颜色,这里可以16进制的颜色,也可以常用的颜色单词*/
    background-repeat:repeat;/*设置平铺方式,repeat就是从左到右,从上到下平铺;repeat-x:从左往右平铺;repeat-y:从上往下平铺;不平铺no-repeat*/
    background-position:left top;/*设置图片位置,left top指左上对齐;还有left bottom;right top;right bottom;center top;center bottom;center center;left center;right center;*/
    /*background-size是CSS3常用的属性*/
}

第二种是链式写法,比如:

body{background:#fff url('图片路径') no-repeat left top;}

个人比较常用的是第二种方式,看哪种方式更适合你,就使用哪种方式。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-10-17
.background{
width:1000px;
height:700px;
background-image:url("bg.jpg");
background-color:red;
background-repeat:no-repeat;
}
图片别太大就行本回答被网友采纳