您的位置:首页 > Web前端 > CSS

CSS实现兼容浏览器的文字阴影效果

2009-09-09 13:10 911 查看
也不记得是哪天了,美工丢来一个页面要做。哇塞!上面居上有文字阴影的效果,一般这种情况下,要么就用图片,要么就是沟通一下把这个不2.0的效果给喀嚓掉就得了。如果只考虑IE的话那当然就一个滤镜就搞定,不过我们得向标准看齐嘛。当时脑瓜子转了转,还真让我给想出办法来了。就是下面这种效果咯。

.title_div {height:30px;border:1px solid #97a3ad; background:#6c7d8d; overflow:hidden; line-height:30px; padding-left:35px; font-weight:bold;}
.title_text { color:#FFF; margin:1px 0 0 0px; position:absolute; z-index:20; float:left;}
.title_shadow { color:#000; margin:2px 0 0 2px; position:absolute; z-index:10; float:left;}


其实这只算是一种取巧的手法了,原理很简单,其实是输入了两次文本,通过定位使其中一个在上方另一个在下方,并加上少许的偏移使之产生阴影的效果。当然,此方法是能通过W3C验证了,但本民工并不觉得这是一种“标准”的做法,还是只在少数需要增强设计的场合使用罢了。

下面是代码:

<mce:style type="text/css"><!--
.title_div {height:30px; background:#6c7d8d; overflow:hidden; line-height:30px; padding-left:35px;}
.title_text { color:#FFF; margin:1px 0 0 0px; position:absolute; z-index:20; float:left;}
.title_shadow { color:#000; margin:2px 0 0 2px; position:absolute; z-index:10; float:left;}
--></mce:style><style type="text/css" mce_bogus="1">
.title_div {height:30px; background:#6c7d8d; overflow:hidden; line-height:30px; padding-left:35px;}
.title_text { color:#FFF; margin:1px 0 0 0px; position:absolute; z-index:20; float:left;}
.title_shadow { color:#000; margin:2px 0 0 2px; position:absolute; z-index:10; float:left;} </style>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>兼容浏览器的文字阴影效果</title>
<mce:style type="text/css"><!--
.title_div {height:30px; background:#6c7d8d; overflow:hidden; line-height:30px; padding-left:35px;}
.title_text { color:#FFF; margin:1px 0 0 0px; position:absolute; z-index:20; float:left;}
.title_shadow { color:#000; margin:2px 0 0 2px; position:absolute; z-index:10; float:left;}
--></mce:style><style type="text/css" mce_bogus="1">.title_div {height:30px; background:#6c7d8d; overflow:hidden; line-height:30px; padding-left:35px;}
.title_text { color:#FFF; margin:1px 0 0 0px; position:absolute; z-index:20; float:left;}
.title_shadow { color:#000; margin:2px 0 0 2px; position:absolute; z-index:10; float:left;}</style>
</head>
<body>
<div class="title_div">
<div class="title_text">兼容浏览器的文字阴影效果</div>
<div class="title_shadow">兼容浏览器的文字阴影效果</div>
</div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: