您好,欢迎访问一九零五行业门户网

CSS+html如何实现背景图片的填充详解

引言:
今天想写个人的欢迎界面,又折腾起了前端,然而真的捉急呀
为了美观点,花多点时间吧,又是凌晨三点了0.0
css实现单张背景图片的填充
实现方式一:直接使用body元素的background-image属性,多个浏览器兼容,基本满足要求
添加background-color: #22c3aa;在加载图片前显示颜色
bug:页面太小时下方会留有空隙
详细属性w3school里面的background属性
<span style="font-size:14px;"><!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>hello world</title> <style type="text/css"> body { margin: 0; background-image: url('bg.jpg'); background-repeat:no-repeat; background-position:0% 0%; background-size:cover; background-color: #22c3aa; } </style> </head> <body> </body> </html> </span>
实现方式二:使用p,图片能自适应浏览器的大小,不会出现body的bug
bug:ie11不兼容,下方会有一个绿线(body背景颜色),十分不美观
参见:html中使背景图片自适应浏览器大小
<span style="font-size:14px;"><!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>hello world</title> <style type="text/css"> body { margin: 0; background-color: #22c3aa; } </style> </head> <body> <!-- <p id="layer1" style="position:absolute; width:100%; height:100%; background-color: #22c3aa; z-index:-1" > <img src="3-bg.jpg" height="100%" width="100%"/> </p> --> </body> </html> </span>
以上就是css+html如何实现背景图片的填充详解的详细内容。
其它类似信息

推荐信息