1、插入背景图片有两种方法,一种是用html的img标签,另一种是利用css的background标签插入。具体 *** 作是首先新建一个html文件,写入两个div,分别用来演示两种方法插入标签:
2、首先是用html标签插入图片,这里直接在img标签中使用src属性就可以插入图片路径就成功了:
3、接着是用css插入,在div中设置class属性为img2,在script标签中使用background标签插入,其中url是标签的路径,no-repeat是设置图片不重复,center是设置照片居中显示:
4、最后给这些标签都设置一些样式,让它们显得美观一些。然后打开浏览器查看效果:
5、打开浏览器,可以看到照片都显示出来了。以上就是html插入照片的方法介绍:
html5中设置整页背景图片的方法是利用css3样式:
写法如下:
img.bg {
/* Set rules to fill background */
min-height: 100%
min-width: 1024px
/* Set up proportionate scaling */
width: 100%
height: auto
/* Set up positioning */
position: fixed
top: 0
left: 0
}
@media screen and (max-width: 1024px) { /* Specific to this particular image */
img.bg {
left: 50%
margin-left: -512px /* 50% */
}
}
效果如:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)