DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS基礎知識
8.2 圖片邊框 border 與 hover 互動
編輯:CSS基礎知識     

一、圖片邊框 border

在「CSS 邊框 border」一節中,我們已經把邊框屬性講得很細。替圖片加上邊框,用的也是同一個 border 屬性,語法完全通用。

語法:

 border-width:像素值; border-style:屬性值; border-color:顏色值; 

註:實務上多採用 border 簡潔寫法,例如「border:1px solid gray;」。

說明:

若忘了 border 各值的含義,請自行回去複習那一節。

舉例 1:

 <!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>圖片邊框border</title>
<style type="text/css">
img { width:60px; height:60px; border:1px solid red; }
</style>
</head>
<body>
<img src="../App_images/lesson/run_cj/cartoongirl.gif" alt=""/>
</body>
</html> 

在瀏覽器中預覽,效果如下:

舉例 2:

 <!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>圖片邊框border</title>
<style type="text/css">
img{width:60px;height:60px;}
img:hover{border:1px solid gray;}
</style>
</head>
<body>
<img src="../App_images/lesson/run_cj/cartoongirl.gif" alt=""/>
</body>
</html> 

在瀏覽器中預覽,效果如下:

分析:

這裡用到了「:hover 偽類」,讓滑鼠移經圖片時才浮現灰色邊框,移開即消失。這類細節互動在圖片列表、產品縮圖上很常見,成本極低但對質感的提升很明顯。

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