<!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>
/* 1.背景色 */
div{
background-color: pink;
width: 600px;
height: 600px;
/* 红绿蓝三原色,a是透明度0-1 */
/* background-color: rgba(0,0,0,.5); */
background-image: url(./images/5.jpg);
background-repeat: no-repeat;
background: blueviolet url(./images/5.jpg) no-repeat center;
/* 不平铺,只显示一张图 */
/* background-repeat: repeat-x; */
/* 沿着水平平铺 */
/* background-repeat: repeat-y; */
/* 沿着垂直平铺 */
/* background-position: 0 0; */
/* 左上角 */
/* background-position: right 0; */
/* 右上角 */
/* background-position: right bottom; */
/* 右下角 */
/* background-position: center center; */
/* 居中 */
}
/* 2.背景图片 */
/* background-image(bgi)
属性值:background-image: url('图片路径');
背景图片中url可以省略引号;
背景图片默认是在水平和垂直方向平铺的
背景图片仅仅是指给盒子起到装饰作用,类似于背景颜色,是不能撑开盒子的 */
/* 3.背景平铺 */
/* 属性名:background-repeat
属性值:repeat--(默认值)水平和垂直方向都平铺
no-repeat--不平铺
repeat-x--沿着水平方向(x轴)平铺
repeat-y--沿着垂直方向(y轴)平铺 */
/* 4.背景位置 */
/* 属性名:background-position(bgp)
属性值:background-position:水平方向位置 垂直方向位置 */
/* 正数:向右向下移动,负数:向左向上移动 */
/* 背景色和背景图只显示在盒子里边 */
/* 背景图位置是英文可以颠倒顺序,如果是数值则不能颠倒位置 */
/* 5.背景相关属性连写形式 */
/* 属性名:background
书写顺序:background: color image repeat position
可以按照需求省略
在PC端,如果盒子大小和背景图片大小一样,此时可以直接写background: url() */
/* 6.img标签和背景图片的区别:
img标签是一个标签,不设置宽高,默认以原尺寸显示
背景图片需要设置div的宽高,背景图片只是装饰CSS样式,不能撑开div标签
img在工作中用来实现比较重要的图片:产品图片
起修饰作用,装饰的图片用背景图 */
</style>
</head>
<body>
<div>div</div>
</body>
</html>