效果如图 思路:div相对定位. 图片默认定位, 文字绝对定位 参考代码 <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title ></ title > < style type = "text/css" > /*div1下面 包含着1个图片和1段文字*/ #div1{ position: relative;/*相对定位*/ width: 267px; height: 140px; } /*图片部分的设置*/ #img1{ /*position: static;默认定位,可以省略*/ width: 100%; height: 100%; } /*文字的设置*/ #span1{ position: absolute;/*绝对定位*/ width: 100%; bottom: 0px;/*离底下0像素*/ left: 0px;/*离左边0像素*/ text-align: center; font-size: 18px; color: white; } </ style > </ head > < body > < div id = "div1" > < span id = "span1" >惬意的海岸,旖旎的风景</ span > < img src = "img/hbfj.jpg" id = "img1" /> </ div > </ body > </ html > 你给一个div 添加背景图,不影响在这个div里面添加文字的,比如 第一种方法、添加一个DIV,采用绝对定位,图片所属DIV为基准。 参考代码如下:
第二种方法、图片作为背景图片。 参考代码如下: <div style= "background:url(abc.jpg) no-repeat left top;" > wenzi </div> |
|
来自: Eagle89 > 《Dreamwaver》