CSS伪对象搞定首字下沉

来源:互联网 发布:微软雅黑mac字体常规 编辑:程序博客网 时间:2024/04/29 18:18

用过word,看过报纸的朋友,是不是对它们的首字下沉效果很感兴趣?

有的时候适当的在web中使用些首字下沉的效果,能为你的web增色不少。

通过伪对象:first-letter可以搞定这个效果:

演示地址:http://www.doyoe.com/model/xhtmlcss/style/first.htm

CSS部分:

.dyfirst {
 width:300px;
 border:1px solid #ddd;
 padding:5px;
 font-size:12px;
}
.dyfirst:first-line {
 color:#050;
}
.dyfirst:first-letter {
 font-size:300%;
 font-weight:bold;
 color:#000;
 float:left;
}

XHTML部分:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="Author" content="飘零雾雨|edzmaster@gmail.com" />
<title>CSS Pseudo-Elements 搞定首字下沉</title>
</head>
<body>
<div class="dyfirst">
To the world you may be one person, but to one person you may be theworld. Never frown, even when you are sad, because you never know who is fallingin love with your smile.
</div>
</body>
</html>

以上的CSS只有.dyfirst:first-letter是用来做首字下沉效果的,其余的两个东东,只是为了让这个效果看起来更明显。同时也把:first-line的用法写了下,毕竟和:first-letter是“胞兄弟”,称不离砣嘛。

用CSS Pseudo-Elements做首字下沉的原理大致就是这样的,这只是一个演示,朋友们可以把效果做得更赞。

 
原创粉丝点击