May 20 2007

用css样式表实现首字大写

Filed under: xhtml/css - ferry @ 18:26 pm

css当中有许多平时很少用的属性,但是这些属性有时候被发掘出来以后就会立刻引起一些人的追逐,首字大写就是这样一种效果。最近越来越多的blogger开始在自己的blog中运用这一方法,东西很简单,下面就来给大家介绍一下用:first-letter伪类来实现这种效果的方法:
:first-letter版本:CSS2 兼容性:IE5.5+

语法:Selector : first-letter { sRules }

说明:设置对象内的第一个字符的样式。
此伪对象仅作用于块对象。内联要素要使用该属性,必须先设定对象的 height 或 width 属性,或者设定 position 属性为 absolute ,或者设定 display 属性为 block 。

在此伪对象中配合使用 font-size 属性和 float 属性可以制作首字下沉效果。
示例:p a:first-letter { color: green }
div:first-letter { color:red;font-size:16px;float:left; }

应用于:IE5.5+ ADDRESS BLOCK QUOTE BODY CENTER DD DIV DL DT FIELDSET FORM Hn LEGEND LI LISTING MARQUEE MENU P PLAINTEXT PRE XMP

目前IE和FF都支持此属性,所以大家不必顾虑兼容性的问题,当然要记得设置float属性哦,不然就不会出现那种大字紧贴几行的效果了。

范例(未设置float属性):
<style>
p{line-height:25px;}
p:first-letter{font-size:50px;line-height:50px;}
</style>
<p>欢迎大家来到<a href="http://homepage.yesky.com"><a href="http://homepage.yesky.com/" class="bluekey" target="_blank">网页</a>陶吧</a></p>
范例(设置float属性为left):
<style>
p{line-height:25px;}
p:first-letter{font-size:50px;line-height:50px;float:left;}
</style>
<p>欢迎大家来到<a href="http://homepage.yesky.com">网页陶吧</a></p>
ths

Comments »

The URI to TrackBack this entry is: http://ferrychu.blogsome.com/2007/05/20/test-2/trackback/

No comments yet.

RSS feed for comments on this post.

Write here

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Ferry Chu
Website Hit Tracking
Copyright © 2007 Chuyujiang