css如何在文档里添加图片

html-css08

css如何在文档里添加图片,第1张

css只能通过背景图形式来给文档添加图片

background-image: url(图片地址)

background: url(图片地址) 0 0 no-repeat

.img1{

background-image: url(1.jpg)

background-size: 200px

}

<div class="img1"></div>

用CSS往图片上嵌入文字有二种方法,分别如下:

第一种方法、添加一个DIV,采用绝对定位,图片所属DIV为基准。

参考代码如下:

1

2

3

4

5

6

<div style="position:relativewidth:100pxheight:100px">

<img src="" alt="" />

<div style="position:absolutewidth:100pxheight:100pxz-indent:2left:0top:0">

文字

</div>

</div>

第二种方法、图片作为背景图片。

参考代码如下:

1

2

3

<div style="background:url(abc.jpg) no-repeat left top">

文字

</div>