本文主要包含CSS,伪元素,三角形,提示框等相关知识,佚名 希望在学习及工作中可以帮助到您
CSS伪元素非常有用,它提供了一种无需多余的DOM元素来实现一些常见的功能的方法,以下利用其实现一个带三角形的tooltip。
下面是DOM结构:
下面是对应的CSS样式:
- <div class="tooltip-wrapper bottom">
- <div class="arrow"></div>
- <div class="content">
- This is content
- </div>
- </div>
- .tooltip-wrapper {
- position: absolute;
- z-index: 9999;
- padding: 5px;
- background: white;
- border: 1px solid #7d7d7d;
- border-radius: 5px;
- }
- .tooltip-wrapper .arrow,
- .tooltip-wrapper .arrow:after {
- position: absolute;
- display: block;
- width: 0;
- height: 0;
- border-color: transparent;
- border-style: solid;
- }
- .tooltip-wrapper .arrow {
- border-width: 11px;
- }
- .tooltip-wrapper .arrow:after {
- content: "";
- border-width: 10px;
- }
- .tooltip-wrapper.bottombottom .arrow {
- top: -11px;
- left: 50%;
- margin-left: -11px;
- border-top-width: 0;
- border-bottom-color: #7d7d7d;
- }
- .tooltip-wrapper.bottombottom .arrow:after {
- top: 1px;
- margin-left: -10px;
- border-top-width: 0;
- border-bottom-color: white;
- }&nb