背景颜色+背景图片
background-color:颜色值;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div
{
width:100px;
height:60px;
}
#div1{background-color: hotpink}
#div2{background-color: #87CEFA;}
</style>
</head>
<body>
<div id="div1">背景颜色为:hotpink</div>
<div id="div2">背景颜色为:#87CEFA</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
p
{
color:white;
background-color: hotpink;
}
</style>
</head>
<body>
<p>
p元素文本颜色为white<br/>
p元素背景颜色为hotpink
</p>
</body>
</html>
background-image:url(图片路径);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div {
width:250px;
height:170px;
background-image: url(img/haizei.png);
/*背景图片所在元素必须设置width,height,默认width,height为0,不显示图片*/
}
</style>
</head>
<body>
<div></div>
</body>
</html>
background-repeat:取值;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div
{
width:200px;
height:100px;
border: 1px solid silver;
background-image: url(img/flower.png);
}
#div2{background-repeat: repeat-x}
#div3{background-repeat: repeat-y}
#div4{background-repeat: no-repeat}
</style>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
</body>
</html>
background-position:像素值/关键字/百分比;
左上角水平,垂直距离
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div
{
width:300px;
height:200px;
border:1px solid silver;
background-image:url(img/judy.png);
background-repeat:no-repeat;
background-position:40px 20px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
垂直位置,水平位置
垂直位置
top、center、bottom
水平位置
left、center、right
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div
{
width:300px;
height:200px;
border:1px solid silver;
background-image:url(img/judy.png);
background-repeat:no-repeat;
background-position:center right;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
background-attachment:取值;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div
{
width:160px;
height:1200px;
border:1px solid silver;
background-image:url(img/judy.png);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
</head>
<body>
<div></div>
</body>
</html>