当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > 使用CSS给图片添加阴影的方法

CSS样式表
提高网页效率的14条注意事项图文
提高网页的效率 Use YSlow to know why your web Slow
学习WEB标准总结的一些CSS/XHTML知识小结
CSS文件可维护、可读性提高指南
Firefox下样式设置宽度奇怪现象
Chrome的hack写法以及CSS的支持程度图示
IE6支持position:fixed完美解决方法
css为图片设置背景图片
ASP、PHP与javascript根据时段自动切换CSS皮肤的代码
css图片切换效果代码[不用js]
css import与link的区别
BS项目中的CSS架构_仅加载自己需要的CSS
div结合css布局bbs首页(div+css布局入门)
css 兼容性问题this.style.cursor=''''hand''''
CSS渐变统计柱形图
跨浏览器的实践:position:fixed 层的固定定位
标准布局常见问题及解决办法
css美化input file按钮的代码方法
重置默认样式 css reset
支持IE6 IE7 Firefox 的纯CSS的下拉菜单

CSS样式表 中的 使用CSS给图片添加阴影的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-09   浏览: 110 ::
收藏到网摘: n/a

一般我们可以使用背景图的方式给图片添加阴影,但对于不固定尺寸的图片如何实现呢?我们可以采取“视觉欺骗大法”——定义渐变边框来实现:

<!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" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title></title>
<style type="text/css" >
body {background:#2e334d;}
img {border:none;}
a.pic-shadow {display:inline-block;zoom:1;padding:1px;background:#262a3f;border:solid #2b3048 1px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;}
a.pic-shadow img {padding:1px;background:#13151f;border:solid #1e2132 1px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;}
</style>
</head>
<body>
<a class="pic-shadow" href="#" title=""><img src="http://www.blueidea.com/articleimg/2009/07/6846/demo.png" alt="" title="" /></a>
</body>
</html>

    下面这段定义是各标准浏览器中圆角定义,用以更专业地欺骗眼睛

border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;

    颜色代码可以在ps中做好外发光效果后拾取。我上面的效果是[柔和]、[扩展0]、[大小5px]、[颜色#000]其余默认

    当然了,特殊要求的话可以使用ie的滤镜来实现更华丽的阴影。