CSS+DIV:让文本字符环绕在你的图片周围

2016-02-19 17:27 19 1 收藏

每个人都希望每天都是开心的,不要因为一些琐事扰乱了心情还,闲暇的时间怎么打发,关注图老师可以让你学习更多的好东西,下面为大家推荐CSS+DIV:让文本字符环绕在你的图片周围,赶紧看过来吧!

【 tulaoshi.com - Web开发 】

  看到上面的效果,你也许以为这是一张带文字的图片而已;呵呵,用你的鼠标去选取文字看看,发现了吧,这完完全全是一张图片和文字的组合,下面我就来介绍它是怎么做的。

  先看看代码:

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

   以下是引用片段:
div id="info"
h2TRACKING YOUR IMAGES/h2
div id="holdit"
img src="/imagelist/06/24/4fnpgj5042e6.jpg" alt="Winnie the pooh" title="Winnie the pooh" /
em class="a420"/em
em class="a430"/em
em class="a400"/em
em class="a370"/em
em class="a340"/em
em class="a300"/em
em class="a270"/em
em class="a250"/em
em class="a240"/em
em class="a230"/em
em class="a230"/em
em class="a340"/em
em class="a340"/em
em class="a360"/em
em class="a540"/em
em class="a540"/em
em class="a540"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a540"/em
em class="a460"/em
em class="a490"/em
em class="a500"/em
em class="a500"/em
p"I shall have to wait until I catch up with it," said Winnie-the-Pooh. "Now, look there." He pointed to the ground in front of him. "What do you see there?"br /
"Tracks," said Piglet. "Paw-marks." He gave a little squeak of excitement. "Oh, Pooh! Do you think it's a--a--a Woozle?"br /
"It may be," said Pooh. "Sometimes it is, and sometimes it isn't. You never can tell with paw- marks."br /
With these few words he went on tracking, and Piglet, after watching him for a minute or two, ran after him. Winnie-the-Pooh had come to a sudden stop, and was bending over the tracks in a puzzled sort of way.br /
"What's the matter?" asked Piglet.br /
"It's a very funny thing," said Bear, "but there seem to be two animals now. This--whatever-it-was--has been joined by another--whatever-it-is--
and the two of them are now proceeding in company. Would you mind coming with me, Piglet, in case they turn out to be Hostile Animals?"br /
Piglet scratched his ear in a nice sort of way, and said that he had nothing to do until Friday, and would be delighted to come, in case it really was a Woozle.br /
"You mean, in case it really is two Woozles," said Winnie-the-Pooh, and Piglet said that anyhow he had nothing to do until Friday. So off they went together./p
/div
/div

   以下是引用片段:
#info h3{ text-align:center;
}
#holdit {width:700px; position:relative; margin:3em auto; padding:10px; border:1px solid #ddd;}
#holdit img {position:absolute; z-index:1; top:10px; left:10px; }
#holdit p { margin:0px; position:relative; z-index:10; line-height:18px; text-align:justify; font-size:10px; font-family:verdana, arial, sans-serif}
#holdit em {display:block; float:left; height:18px; clear:left; overflow:hidden; }
.a230 {width:230px;}
.a240 {width:240px;}
.a250 {width:250px;}
.a270 {width:270px;}
.a300 {width:300px;}
.a340 {width:340px;}
.a360 {width:360px;}
.a370 {width:370px;}
.a400 {width:400px;}
.a420 {width:420px;}
.a430 {width:430px;}
.a460 {width:460px;}
.a490 {width:490px;}
.a500 {width:500px;}
.a540 {width:540px;}
.a550 {width:550px;}

  接着我们来分析一下红色加亮的部分:

  首先将包容对象#holdit设置成相对定位(确保等下的img绝对定位以它左上角为原点)

  接着把#holdit里面的img设成绝对定位且z-index高度为1,这样img就脱离文档流了

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

  将em标签设置左浮动,高度和p的ling-height要一样,再根据图片的图案分别设置每个em的宽度(记得要用clear来清除浮动)

  最后把P设置成相对定位且z-index高度设置大于img的数值

  其实我们也可以直接将图片作为为#holdit的背景,这样就不需要专门为img来设置CSS了

STYLE
#info h3{ text-align:center;
}
#holdit {width:700px; position:relative; margin:3em auto; padding:10px; border:1px solid #ddd;}
#holdit img {position:absolute; z-index:1; top:10px; left:10px; }
#holdit p { margin:0px; position:relative; z-index:10; line-height:18px; text-align:justify; font-size:10px; font-family:verdana, arial, sans-serif}
#holdit em {display:block; float:left; height:18px; clear:left; overflow:hidden; }
.a230 {width:230px;}
.a240 {width:240px;}
.a250 {width:250px;}
.a270 {width:270px;}
.a300 {width:300px;}
.a340 {width:340px;}
.a360 {width:360px;}
.a370 {width:370px;}
.a400 {width:400px;}
.a420 {width:420px;}
.a430 {width:430px;}
.a460 {width:460px;}
.a490 {width:490px;}
.a500 {width:500px;}
.a540 {width:540px;}
.a550 {width:550px;}
/STYLE

div id="info"
h2TRACKING YOUR IMAGES/h2
div id="holdit"
img src="/imagelist/06/24/4fnpgj5042e6.jpg" alt="Winnie the pooh" title="Winnie the pooh" /
em class="a420"/em
em class="a430"/em
em class="a400"/em
em class="a370"/em
em class="a340"/em
em class="a300"/em
em class="a270"/em
em class="a250"/em
em class="a240"/em
em class="a230"/em
em class="a230"/em
em class="a340"/em
em class="a340"/em
em class="a360"/em
em class="a540"/em
em class="a540"/em
em class="a540"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a550"/em
em class="a540"/em
em class="a460"/em
em class="a490"/em
em class="a500"/em
em class="a500"/em
p"I shall have to wait until I catch up with it," said Winnie-the-Pooh. "Now, look there." He pointed to the ground in front of him. "What do you see there?"br /
"Tracks," said Piglet. "Paw-marks." He gave a little squeak of excitement. "Oh, Pooh! Do you think it's a--a--a Woozle?"br /
"It may be," said Pooh. "Sometimes it is, and sometimes it isn't. You never can tell with paw- marks."br /
With these few words he went on tracking, and Piglet, after watching him for a minute or two, ran after him. Winnie-the-Pooh had come to a sudden stop, and was bending over the tracks in a puzzled sort of way.br /
"What's the matter?" asked Piglet.br /
"It's a very funny thing," said Bear, "but there seem to be two animals now. This--whatever-it-was--has been joined by another--whatever-it-is--
and the two of them are now proceeding in company. Would you mind coming with me, Piglet, in case they turn out to be Hostile Animals?"br /
Piglet scratched his ear in a nice sort of way, and said that he had nothing to do until Friday, and would be delighted to come, in case it really was a Woozle.br /
"You mean, in case it really is two Woozles," said Winnie-the-Pooh, and Piglet said that anyhow he had nothing to do until Friday. So off they went together./p
/div
/div
运行代码复制代码另存代码

来源:https://www.tulaoshi.com/n/20160219/1615265.html

延伸阅读
标签: Web开发
由于现在很多div+css中的图片都写在了css里面。 直接用浏览器的另存为已经不能完全保存到本地 我在网上收集了一些方法,和一些自己的实践,希望对你有所帮助 第一:苦力型 查看网页源文件,然后找到css路径,直接输入到ie地址框内下载既可。打开css找出里面的图片一个一个下载 第二:偷懒型 保存到本...
标签: Web开发
网页布局技巧实例,想让DIV居中,如何编写CSS? div居中的设置该如何编写css?我们在传统的表格布局中,只要设置表格的居中属性就实现了居中的块元素。应用div css网站布局,div的居中该如何编写css来控制它呢? 主要的样式定义如下: body {text-align: center;} #center { margin-right: auto; margin-left: auto;...
标签: 服务器
Linux系统中tr命令删除和替换文本字符的基本用法   通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能。您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符。您也可以用它来除去重复字符。这就是所有 tr 所能够做的。 tr用来从标准输入中通过替换或删除操作进行字...
标签: Web开发
css对文字的布局上没有靠容器底部对齐的参数,目前使用的一个不错的方法也比较好.就是用position属性来解决,看下面的代码,用position的相对和绝对定位功能也轻松的实现了,文字靠近div低部对齐,并且靠近的距离还可以精确到像素,自己可以调节,是不是很不错呢? !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://w...
标签: Web开发
一、什么是DIV+CSS? “DIV + CSS” 是最新WEB标准的一个典型的应用。 一般来说,网页主要由三部分组成:结构(Structure)、表现(Presentation)和行为(Behavior)等。 结构主要包括例如DIV在内的一系列的HTML(XHTML)标签,表现主要包括CSS(层叠样式表:Cascading Style Sheets), 行为主要包括例如对象模型(如W3C DOM)、ECMAScript等...

经验教程

217

收藏

59
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部