Skip to content

Commit 8ef66df

Browse files
committed
Convert popover's arrows to generated CSS content via :before/:after
1 parent 2ae5fdf commit 8ef66df

File tree

2 files changed

+75
-53
lines changed

2 files changed

+75
-53
lines changed

js/src/popover.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const Popover = (($) => {
2828
trigger : 'click',
2929
content : '',
3030
template : '<div class="popover" role="tooltip">'
31-
+ '<div class="popover-arrow"></div>'
3231
+ '<h3 class="popover-title"></h3>'
3332
+ '<div class="popover-content"></div></div>'
3433
})
@@ -44,8 +43,7 @@ const Popover = (($) => {
4443

4544
const Selector = {
4645
TITLE : '.popover-title',
47-
CONTENT : '.popover-content',
48-
ARROW : '.popover-arrow'
46+
CONTENT : '.popover-content'
4947
}
5048

5149
const Event = {

scss/_popover.scss

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,79 +23,103 @@
2323
&.bs-tether-element-attached-bottom {
2424
margin-top: -$popover-arrow-width;
2525

26-
.popover-arrow {
27-
bottom: -$popover-arrow-outer-width;
26+
&::before,
27+
&::after {
2828
left: 50%;
29+
border-bottom-width: 0;
30+
}
31+
32+
&::before {
33+
bottom: -$popover-arrow-outer-width;
2934
margin-left: -$popover-arrow-outer-width;
3035
border-top-color: $popover-arrow-outer-color;
31-
border-bottom-width: 0;
32-
&::after {
33-
bottom: 1px;
34-
margin-left: -$popover-arrow-width;
35-
content: "";
36-
border-top-color: $popover-arrow-color;
37-
border-bottom-width: 0;
38-
}
36+
}
37+
38+
&::after {
39+
bottom: -($popover-arrow-outer-width - 1);
40+
margin-left: -$popover-arrow-width;
41+
border-top-color: $popover-arrow-color;
3942
}
4043
}
4144

4245
&.popover-right,
4346
&.bs-tether-element-attached-left {
4447
margin-left: $popover-arrow-width;
4548

46-
.popover-arrow {
49+
&::before,
50+
&::after {
4751
top: 50%;
52+
border-left-width: 0;
53+
}
54+
55+
&::before {
4856
left: -$popover-arrow-outer-width;
4957
margin-top: -$popover-arrow-outer-width;
5058
border-right-color: $popover-arrow-outer-color;
51-
border-left-width: 0;
52-
&::after {
53-
bottom: -$popover-arrow-width;
54-
left: 1px;
55-
content: "";
56-
border-right-color: $popover-arrow-color;
57-
border-left-width: 0;
58-
}
59+
}
60+
61+
&::after {
62+
left: -($popover-arrow-outer-width - 1);
63+
margin-top: -($popover-arrow-outer-width - 1);
64+
border-right-color: $popover-arrow-color;
5965
}
6066
}
6167

6268
&.popover-bottom,
6369
&.bs-tether-element-attached-top {
6470
margin-top: $popover-arrow-width;
6571

66-
.popover-arrow {
67-
top: -$popover-arrow-outer-width;
72+
&::before,
73+
&::after {
6874
left: 50%;
69-
margin-left: -$popover-arrow-outer-width;
7075
border-top-width: 0;
76+
}
77+
78+
&::before {
79+
top: -$popover-arrow-outer-width;
80+
margin-left: -$popover-arrow-outer-width;
7181
border-bottom-color: $popover-arrow-outer-color;
72-
&::after {
73-
top: 1px;
74-
margin-left: -$popover-arrow-width;
75-
content: "";
76-
border-top-width: 0;
77-
border-bottom-color: $popover-arrow-color;
78-
}
82+
}
83+
84+
&::after {
85+
top: -($popover-arrow-outer-width - 1);
86+
margin-left: -$popover-arrow-width;
87+
border-bottom-color: $popover-title-bg;
88+
}
89+
90+
// This will remove the popover-title's border just below the arrow
91+
.popover-title::before {
92+
position: absolute;
93+
top: 0;
94+
left: 50%;
95+
display: block;
96+
width: 20px;
97+
margin-left: -10px;
98+
content: "";
99+
border-bottom: 1px solid $popover-title-bg;
79100
}
80101
}
81102

82103
&.popover-left,
83104
&.bs-tether-element-attached-right {
84105
margin-left: -$popover-arrow-width;
85106

86-
.popover-arrow {
107+
&::before,
108+
&::after {
87109
top: 50%;
110+
border-right-width: 0;
111+
}
112+
113+
&::before {
88114
right: -$popover-arrow-outer-width;
89115
margin-top: -$popover-arrow-outer-width;
90-
border-right-width: 0;
91116
border-left-color: $popover-arrow-outer-color;
92-
&::after {
93-
right: 1px;
94-
bottom: -$popover-arrow-width;
95-
content: "";
96-
border-right-width: 0;
97-
border-left-color: $popover-arrow-color;
98-
}
117+
}
118+
119+
&::after {
120+
right: -($popover-arrow-outer-width - 1);
121+
margin-top: -($popover-arrow-outer-width - 1);
122+
border-left-color: $popover-arrow-color;
99123
}
100124
}
101125
}
@@ -120,21 +144,21 @@
120144
//
121145
// .popover-arrow is outer, .popover-arrow::after is inner
122146

123-
.popover-arrow {
124-
&,
125-
&::after {
126-
position: absolute;
127-
display: block;
128-
width: 0;
129-
height: 0;
130-
border-color: transparent;
131-
border-style: solid;
132-
}
147+
.popover::before,
148+
.popover::after {
149+
position: absolute;
150+
display: block;
151+
width: 0;
152+
height: 0;
153+
border-color: transparent;
154+
border-style: solid;
133155
}
134-
.popover-arrow {
156+
157+
.popover::before {
158+
content: "";
135159
border-width: $popover-arrow-outer-width;
136160
}
137-
.popover-arrow::after {
161+
.popover::after {
138162
content: "";
139163
border-width: $popover-arrow-width;
140164
}

0 commit comments

Comments
 (0)