CSS引入图片文件
在CSS中,可以用background-image:url(你的图片地址)或background:url(你的图片地址)来引入图片,展现到网页中。
<div id="bgimg"></div> #bgimg { background: #333 url(图片路径) center center no-repeat; }
第一个参数,图片底层的背景颜色,第二个参数,图片路径,第三个参数,图片上下的相对位置(其他参数left,right),第四个参数,图片左右的相对位置(top,bottom),第五个参数,图片的重复(其他参数 repeat,repeat-x,repeat-y)。
示例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>背景图片设置</title> <style> .demo{ position:fixed; top: 0; left: 0; width:100%; height:100%; min-width: 1000px; z-index:-10; zoom: 1; background-color: #fff; background: url(1.png); background-repeat: no-repeat; background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-position: center 0; } </style> </head> <body> <div class="demo"></div> </body> </html>
效果图:
说明:
background属性是一个简写属性,可以在一个声明中设置所有的背景属性。
background属性就是专门设置背景的属性,可以设置背景色,也可以设置背景图片。
下面看看background可以设置的属性:
background-color: 规定要使用的背景颜色。
background-position: 规定背景图像的位置。
background-size: 规定背景图片的尺寸。
background-repeat :规定如何重复背景图像。
background-origin :规定背景图片的定位区域。
background-clip: 规定背景的绘制区域。
background-attachment: 规定背景图像是否固定或者随着页面的其余部分滚动。
background-image :规定要使用的背景图像。
元素的背景是元素的总大小,包括填充和边界(但不包括边距)。默认情况下,background-image放置在元素的左上角,并重复垂直和水平方向。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)