將元素 width:0; height:0;,設定粗邊框,三面透明、一面實色,即形成三角形。方向由實色邊決定:
border-bottom-color 實色 → 向上三角border-top-color 實色 → 向下三角border-left-color 實色 → 向右三角border-right-color 實色 → 向左三角<div class="container">
<s class="arrow-outer"></s>
<i class="arrow-inner"></i>
<div class="content">提示內容</div>
</div>
.container { position: absolute; top: 30px; left: 40px; width: 200px; height: 100px; }
.arrow-outer, .arrow-inner {
position: absolute; display: block; width: 0; height: 0; font-size: 0; line-height: 0;
border: 10px solid transparent; border-style: dashed dashed solid dashed;
}
.arrow-outer {
top: -20px; left: 20px; border-bottom-color: #666; /* 外層灰色邊框色 */
}
.arrow-inner {
top: -9px; left: -10px; border-bottom-color: #fff; /* 內層白色蓋住外層邊框內側 */
}
.content {
position: absolute; width: 100%; height: 100%; background: #fff;
border: 1px solid #666; border-radius: 3px; padding: 5px;
box-shadow: 3px 3px 4px #999;
/* IE 陰影相容 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#999999');
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#999999')";
}
border-radius(IE9+)。background-image: url(data:image/svg+xml...) 或 clip-path 簡化結構。