background-color
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>背景色title>
<style>
div {
width: 200px;
height: 200px;
background-color: pink;
}
style>
head>
<body>
<div>div>
body>
html>
background-image
描述了元素的背景图像。实际开发中常见于logo或者一些装饰性的小图片或者是超大的背景图片,其优点是非常便于控制位置(精灵图也是一种运用场景)
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>背景图片title>
<style>
div {
width: 800px;
height: 800px;
background-image: url(images/xjj.png);
}
style>
head>
<body>
<div>div>
body>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>背景图片title>
<style>
div {
width: 800px;
height: 800px;
background-image: url(images/xjj.png);
/* 背景图片不平铺 */
background-repeat: no-repeat;
}
style>
head>
<body>
<div>div>
body>
html>