1515// - https://stackoverflow.com/q/50686342
1616// - https://github.com/exacti/floating-labels
1717
18- // _______________________________
19- // |____________________________ |
20- // | | <== label
21- // | | |
22- // |____________________________ | | <== input
23- // |_______________________________ |
18+ // __________________________________
19+ // |_______________________________ |
20+ // | | <== label
21+ // | | |
22+ // |_______________________________ | | <== input
23+ // |__________________________________ |
2424//
25- // ______________________________
26- // | top: 0 | |
27- // | | |
28- // |____________________________ | |
29- // | |
30- // |_______________________________ |
25+ // __________________________________
26+ // | top: 0 | |
27+ // | | |
28+ // |_______________________________ | |
29+ // | |
30+ // |__________________________________ |
3131//
32- // ____________________________
33- // | top: -label height (-21px) |
34- // | |
35- // |____________________________|__
36- // | |
37- // | |
38- // | |
32+ // _______________________________
33+ // | top: - label height (-17.4px) |
3934// | |
40- // |_______________________________|
35+ // |_______________________________|__
36+ // | |
37+ // | |
38+ // | |
39+ // | |
40+ // |__________________________________|
4141//
42- // ____________________________
43- // | top: -21px + (21px / 2.5) |
44- // |_ _ _ _ _ _ _ _ _ _ _ _ _ _ |__
45- // |____________________________ | |
46- // | |
47- // | |
48- // | |
49- // |_______________________________ |
42+ // _______________________________
43+ // | top: - 17.4px * 3/5 |
44+ // |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |__
45+ // |_______________________________ | |
46+ // | |
47+ // | |
48+ // | |
49+ // |__________________________________ |
5050//
51- // top: - label height + (label height / 2.5)
51+ // top: - label height * 3/5
5252//
53- $label-height-sm : $font-size-sm * $input- line-height ; // 21px
54- $label-top-position-sm : #{ - $label-height-sm + $label-height-sm / 2.5 } ; // -21px + (21px / 2.5) = -12.6px
55- $label-height-md : $font-size-base * $input- line-height ; // 24px
56- $label-top-position-md : #{ - $label-height-md + $label-height-md / 2.5 } ; // -24px + (24px / 2.5) = -14.4px
57- $label-height-lg : $font-size-lg * $input- line-height ; // 30px
58- $label-top-position-lg : #{ - $label-height-lg + $label-height-lg / 2.5 } ; // -30px + (30px / 2.5) = -18px
53+ $label-height-sm : $font-size-sm * $line-height-sm ; // 17.4px
54+ $label-top-position-sm : $label-height-sm * 3 / 5 ; // 17.4px * 3/5 = 10.44px
55+ $label-height-md : $font-size-base * $line-height-sm ; // 20px
56+ $label-top-position-md : $label-height-md * 3 / 5 ; // 20px * 3/5 = 12px
57+ $label-height-lg : $font-size-lg * $line-height-sm ; // 25px
58+ $label-top-position-lg : $label-height-lg * 3 / 5 ; // 25px * 3/5 = 15px
5959
6060@mixin label-common {
6161 // Breaks flexbox :-/
@@ -68,6 +68,9 @@ $label-top-position-lg: #{- $label-height-lg + $label-height-lg / 2.5}; // -30px
6868 // Truncate the text label if larger than the input
6969 max-width : calc (100% - #{$input-border-width * 2 } );
7070 @include text-truncate ();
71+
72+ // Instead of 1.5 https://github.com/twbs/bootstrap/blob/v5.0.0-beta3/scss/_variables.scss#L440
73+ line-height : $line-height-sm ;
7174}
7275
7376// stylelint-disable declaration-no-important
@@ -158,25 +161,44 @@ $transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
158161
159162 + label ,
160163 + label .label-sm {
161- top : $label-top-position-sm ;
164+ top : - $label-top-position-sm ;
162165 font-size : $font-size-sm ;
163166 // https://stackoverflow.com/a/44156191
164167 // [Safari bug with transition and translateY: “jumping” element](https://stackoverflow.com/q/57960955)
165168 // transform: translateY(-55%);
166169 }
167170 + label .label-md {
168- top : $label-top-position-md ;
171+ top : - $label-top-position-md ;
169172 font-size : $font-size-base ;
170173 }
171174 + label .label-lg {
172- top : $label-top-position-lg ;
175+ top : - $label-top-position-lg ;
173176 font-size : $font-size-lg ;
174177 }
175178}
176179
177180.floating-label {
178181 position : relative ;
179182
183+ // FIXME Cannot use min-height or margin-top: breaks input-group
184+ //
185+ // FIXME Cannot set correct margin-top when .label-md or .label-lg is used
186+ // [Apply style to parent if it has child with CSS](https://stackoverflow.com/q/21252551)
187+ //
188+ // https://github.com/twbs/bootstrap/blob/v5.0.0-beta3/scss/_variables.scss#L722
189+ //
190+ // Should we also add the input focus border width ($input-btn-focus-width) to the height?
191+ // => This is not what is done for inputs with Bootstrap v5.0.0-beta3
192+ //
193+ // min-height: calc(#{$input-height} + #{$label-top-position-sm});
194+ // margin-top: $label-top-position-sm;
195+ // &.form-control-sm {
196+ // margin-top: $label-top-position-sm;
197+ // }
198+ // &.form-control-lg {
199+ // margin-top: $label-top-position-sm;
200+ // }
201+
180202 > select {
181203 @include label-above-input ();
182204 }
0 commit comments