Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/scss
diff options
context:
space:
mode:
authorMark Otto <markdotto@gmail.com>2021-06-18 05:58:31 +0300
committerXhmikosR <xhmikosr@gmail.com>2021-06-22 20:11:39 +0300
commited13d0155905533e3f0f7c97b99a7803994e0953 (patch)
tree6da992233320ce7e059d3ba4859a7768d0663d9c /scss
parent290b9ee2cde5a0182e1a53116ef626bd6c0c9cad (diff)
Update the divide() function
Diffstat (limited to 'scss')
-rw-r--r--scss/_functions.scss41
-rw-r--r--scss/mixins/_grid.scss2
2 files changed, 30 insertions, 13 deletions
diff --git a/scss/_functions.scss b/scss/_functions.scss
index 2d3478bfad..870f36790f 100644
--- a/scss/_functions.scss
+++ b/scss/_functions.scss
@@ -221,26 +221,43 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
}
@function divide($dividend, $divisor, $precision: 10) {
- $sign: if($dividend > 0 and $divisor > 0, 1, -1);
+ $sign: if($dividend > 0 and $divisor > 0 or $dividend < 0 and $divisor < 0, 1, -1);
$dividend: abs($dividend);
$divisor: abs($divisor);
- $quotient: 0;
- $remainder: $dividend;
@if $dividend == 0 {
@return 0;
}
@if $divisor == 0 {
@error "Cannot divide by 0";
}
- @if $divisor == 1 {
- @return $dividend;
- }
- @while $remainder >= $divisor {
- $quotient: $quotient + 1;
- $remainder: $remainder - $divisor;
+ $remainder: $dividend;
+ $result: 0;
+ $factor: 10;
+ @while ($remainder > 0 and $precision >= 0) {
+ $quotient: 0;
+ @while ($remainder >= $divisor) {
+ $remainder: $remainder - $divisor;
+ $quotient: $quotient + 1;
+ }
+ $result: $result * 10 + $quotient;
+ $factor: $factor * .1;
+ $remainder: $remainder * 10;
+ $precision: $precision - 1;
+ @if ($precision < 0 and $remainder >= $divisor * 5) {
+ $result: $result + 1;
+ }
}
- @if $remainder > 0 and $precision > 0 {
- $remainder: divide($remainder * 10, $divisor, $precision - 1) * .1;
+ $result: $result * $factor * $sign;
+ $dividend-unit: unit($dividend);
+ $divisor-unit: unit($divisor);
+ $unit-map: (
+ "px": 1px,
+ "rem": 1rem,
+ "em": 1em,
+ "%": 1%
+ );
+ @if ($dividend-unit != $divisor-unit and map-has-key($unit-map, $dividend-unit)) {
+ $result: $result * map-get($unit-map, $dividend-unit);
}
- @return ($quotient + $remainder) * $sign;
+ @return $result;
}
diff --git a/scss/mixins/_grid.scss b/scss/mixins/_grid.scss
index cf5ab7fa2b..f398cd42ae 100644
--- a/scss/mixins/_grid.scss
+++ b/scss/mixins/_grid.scss
@@ -29,7 +29,7 @@
@mixin make-col($size: false, $columns: $grid-columns) {
@if $size {
flex: 0 0 auto;
- width: percentage(divide($size, $columns));
+ width: divide(100%, divide($columns, $size));
} @else {
flex: 1 1 0;