<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>display模式转换</title> <style> body { background-color: green;/*背景颜色设置*/ background-image: url("0.jpg");/*设置背景图片*/ background-repeat: no-repeat;/*背景不平铺,图片有多大显示多大。没有设置就默认背景平铺*/ background-repeat: repeat-x;/*背景横向平铺*/ background-repeat: repeat-y;/*背景纵向平铺*/ background-attachment: fixed;/*背景固定,默认是滚动的*/ /*background属性的值的书写顺序官方并没有强制标准的。为了可读性,建议大家如下写:*/ /*background:背景颜色 背景图片地址 背景平铺 背景滚动 背景位置*/ } div{ width: 500px; height: 400px; background-color: blue; background-image: url("12.jpg"); background-repeat: no-repeat; /*top上 left左 right右 bottom下 。 background-position: x y */ /*position如果只写一个值,那么默认水平居中*/ background-position: center center;/*这是设置水平和垂直居中*/ } </style> </head> <body> </body> </html>