<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
html{width:100%
height:100%}
body{width:100%
height:100%
background: url(../1.jpg) no-repeat
background-size:cover /*这里设置了背景图片为覆盖,以填满整个容器*/
}
</style>
</head>
<body>
</body>
</html>
需要准备的材料分别有:电脑、浏览器、html编辑器。
1、首先,打开html编辑器,新建html文件,例如:index.html。
2、在index.html中的<style>标签中,输入css代码:body {background: url(image.jpg) no-repeatbackground-size: 300px}。
3、浏览器运行index.html页面,此时背景图片成功用css等比例缩小到了300px宽度的大小。