您的位置:首页 > 技术中心 > 前端框架 >

css 怎么引入图片文件

时间:2020-12-30 10:02

css引入图片文件的方法:1、通过“background-image:url(图片地址)”方法来引入;2、使用“background:url(图片地址)”方法来引入图片,展现到网页中即可。

本教程操作环境:Dell G3电脑、Windows7系统、HTML5&&CSS3版本。

推荐:《css视频教程》

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>

效果图:

6747a590f497936e5b084c002d7bd6b.png

说明:

background属性是一个简写属性,可以在一个声明中设置所有的背景属性。

background属性就是专门设置背景的属性,可以设置背景色,也可以设置背景图片。

下面看看background可以设置的属性:

background-color: 规定要使用的背景颜色。

background-position: 规定背景图像的位置。

background-size: 规定背景图片的尺寸。

background-repeat :规定如何重复背景图像。

background-origin :规定背景图片的定位区域。

background-clip: 规定背景的绘制区域。

background-attachment: 规定背景图像是否固定或者随着页面的其余部分滚动。

background-image :规定要使用的背景图像。

元素的背景是元素的总大小,包括填充和边界(但不包括边距)。默认情况下,background-image放置在元素的左上角,并重复垂直和水平方向。

以上就是css 怎么引入图片文件的详细内容,更多请关注www.gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游