DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS詳解
純 CSS 打造無圖片、帶箭頭的 DIV 提示框
編輯:CSS詳解     

下面這個範例展示如何在不使用任何圖片的前提下,純靠 CSS 做出帶有箭頭的 DIV 提示框,並藉由 border 的三角形技巧呈現指向效果,同時兼顧了陰影與跨瀏覽器的相容處理。

<html>
<head>
<title>純CSS無圖片帶箭頭的DIV方框</title>
<style>
div.container{
  position:absolute;
  top:30px;
  left:40px;
  font-size: 9pt;
  display:block;
  height:100px;
  width:200px;
  background-color:transparent;
  *border:1px solid #666;
}
s{
  position:absolute;
  top:-20px;
  *top:-22px;
  left:20px;
  display:block;
  height:0;
  width:0;
  font-size: 0;
  line-height: 0;
  border-color:transparent transparent #666 transparent;
  border-style:dashed dashed solid dashed;
  border-width:10px;
}
i{
  position:absolute;
  top:-9px;
  *top:-9px;
  left:-10px;
  display:block;
  height:0;
  width:0;
  font-size: 0;
  line-height: 0;
  border-color:transparent transparent #fff transparent;
  border-style:dashed dashed solid dashed;
  border-width:10px;
}
.content{
  border:1px solid #666;
  -moz-border-radius:3px;
  -webkit-border-radius:3px;
  position:absolute;
  background-color:#fff;
  width:100%;
  height:100%;
  padding:5px;
  *top:-2px;
  *border-top:1px solid #666;
  *border-left:none;
  *border-right:none;
  *height:102px;
  box-shadow: 3px 3px 4px #999;
  -moz-box-shadow: 3px 3px 4px #999;
  -webkit-box-shadow: 3px 3px 4px #999;
  /* For IE 5.5 - 7 */
  filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#999999');
  /* For IE 8 */
  -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#999999')";
}
</style>
</head>
<body>
<div class="container">
<div class="content"><br>這是框中的文字,可動態顯示。高度自動增加,應該不錯吧^_^</div>
<s>
<i></i>
</s>
</div>
<br />
</body>
</html>

關鍵在於用 s 與 i 兩個空標籤,透過把元素的寬高設為 0、只保留 border,做出上下兩層三角形:外層深色三角形當作箭頭邊框,內層白色三角形蓋住接縫,從而拼出一個帶描邊的箭頭。內容區則加上圓角與陰影,並用 filter 為舊版 IE 補上陰影效果。

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