css空心三角形箭頭矩形效果

antzone發表於2017-04-12

分享一段程式碼例項,它實現了帶有三角形箭頭的矩形效果。

箭頭是空心的,程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
/*提示框*/
.msg {
  position: relative;
  width: 200px;
  height: 100px;
  border: 1px solid #ccc;
  box-shadow: 0 0 10px 2px #ccc;
}
.msg .triangle {
  position: absolute;
  top: 100%;
  left: calc((100% - 10px) / 2);
  width: 0;
  height: 0;
  border: 10px solid transparent;
  border-top-color: #ccc;
}
.msg .triangle:after {
  content: "";
  position: absolute;
  top: -11px;
  left: -9px;
  width: 0;
  height: 0;
  border: 9px solid transparent;
  border-top-color: white;
}
</style>
</head>
<body>
  <div class="msg">
    <div class="triangle"></div>
  </div>
</body>
</html>

相關文章