標籤:
這裡做一個帶箭頭的彈出層。
1、如果瀏覽器不支援CSS3,我們可以用border類比。但是這個時候箭頭不能帶邊框,即純色,不太好看,這個時候我們可以利用兩個b標籤實現:
首先需要製作一個向上的箭頭,箭頭的顏色為彈出層邊框顏色,其它方向可以模仿做出來。
.arrow-outer{ width:0px;height:0px;display:block;border-bottom:10px solid #AFAFAF;border-left:10px solid transparent;border-right:10px solid transparent; /*製作上三角*/}然後製作一個比它小點的箭頭,箭頭的顏色就是彈出層主體的顏色,覆蓋在大的箭頭上面。
<!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=gb2312" /><title>彈出層測試</title><script type="text/javascript" src="jquery-1.9.1.js"></script><style type="text/css">*{margin:0;padding:0;font-family:微軟雅黑}.content{margin-left:400px;margin-top:400px;}.colorbox{width:200px;height:100px;border:1px solid #AFAFAF;border-radius:3px;box-shadow:1px 5px 5px #EFEFEF;margin-top:10px;}.arrow-range{border:0px solid #AFAFAF;width:20px;height:10px;left:10px;position:relative;top:-10px;}.arrow-outer{ width:0px;height:0px;display:block;border-bottom:10px solid #AFAFAF;border-left:10px solid transparent;border-right:10px solid transparent; /*製作上三角*/}.arrow-inner{width:0px;height:0px;display:block;border-bottom:9px solid #FFFFFF;border-left:9px solid transparent;border-right:9px solid transparent;position:relative;left:1.4px;top:-8px;}</style></head><body><div class="content"><button>彈出</button><div class="colorbox"><div class="arrow-range"><b class="arrow-outer"></b><b class="arrow-inner"></b></div></div></div></body>樣式顯示為:
2、如果瀏覽器支援CSS3,就更好辦了,箭頭可以理解為一個矩形的邊角,這個時候可以定義一個div層,將它旋轉到指定位置,這裡我們旋轉45度。
然後再在這個div層加個父div層,如果超過這個div層則隱藏。具體代碼為:
<!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=gb2312" /> <title>彈出層測試</title> <script type="text/javascript" src="jquery-1.9.1.js"></script> <style type="text/css"> *{margin:0;padding:0;font-family:微軟雅黑} .content{margin-left:400px;margin-top:400px;} .colorbox{width:200px;height:100px;border:1px solid #AFAFAF;border-radius:3px;box-shadow:1px 3px 3px #DFDFDF; margin-top:10px;} .arrow-outer{width:12px;height:7px;position:relative;top:-7px;left:10px;overflow:hidden} .arrow{border:1px solid #AFAFAF;width:10px;height:10px;position:relative;top:2px; -webkit-transform:rotate(45deg);-o-transform:rotate(45deg);background:#FFFFFF; -moz-transform:rotate(45deg);} </style> </head> <body> <div class="content"> <button>彈出</button> <div class="colorbox"> <div class="arrow-outer"> <div class="arrow"></div> </div> </div> </div> </body> </html>
具體效果為:
jquery彈出層 +CSS箭頭製作