DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS進階教程
用 CSS 給任意尺寸圖片添加陰影
編輯:CSS進階教程     

一般我們可以用背景圖的方式給圖片添加陰影,但對於尺寸不固定的圖片該怎麼辦?這裡可以採用「視覺欺騙大法」——定義漸變邊框來實現:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://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="https://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;

顏色代碼可以在 Photoshop 中做好外發光效果後拾取。我上面的效果採用 [柔和]、[擴展 0]、[大小 5px]、[顏色 #000],其餘為默認。

當然了,若有特殊需求,也可以使用 IE 的濾鏡來實現更華麗的陰影。總體思路是透過外層與內層兩組漸變邊框疊加,模擬出柔和的立體光影,讓任意尺寸的圖片都能擁有專業的陰影效果。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved