Incompatible units: 'rem' and 'px' - Bootstrap 4.3.1 - sass

I am getting "Incompatible units: 'rem' and 'px'" when overriding the Bootstrap 4.3.1 variables in a custom override sass file.
I have tried positioning following paths on custom sass file on top of the file and last line of the file as instructed on Bootstrap 4 documentation.
#import "node_modules/bootstrap/scss/functions";
#import "node_modules/bootstrap/scss/variables";
#import "node_modules/bootstrap/scss/mixins";
Error in terminal
ERROR in ./src/scss/main.scss (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/scss/main.scss)
Module build failed:
$custom-select-feedback-icon-padding-right: calc((1em + #{2 * $custom-select-padding-y}) * 3 / 4 + #{$custom-select-padding-x + $custom-select-indicator-padding}) !default;
^
Incompatible units: 'rem' and 'px'.

Remove <br> from the SCSS file first and this the problem of calc() function not the problem of px or rem.
NOTE
calc() function is the inbuilt function of CSS, so whenever you call calc() in SCSS, you need to use #{} technique to use the variable
height: calc(100% - #{$body_padding})
Now I give you one example
$custom-select-padding-y = 50px;
$custom-select-feedback-icon-padding-right: calc((1em + #{2 * 50px}) * 3 / 4 + #{$custom-select-padding-x + $custom-select-indicator-padding}) !default;
2 * 50px = 100px and so on after that, it cant calculate 1em + {random px} so, its return undefined and compiler give error.
calc() calculates 2 * 5px = 10px or 2 * 1rem = 32px.
calc() cant calculate 2rem + 1em, 1rem + 1px etc.

Related

Change SASS variables based on screen width

Is it possible to change sass variable based on screen width? I want my $font-size to be 1.5rem on tablet and 1.4rem on mobile so my headings change dynamically.
I tried sth like this:
$font-size: 1.6rem;
#include respond(tab-big) {
$font-size: 1.5rem;
}
#include respond(mobile) {
$font-size: 1.4rem;
}
$font-size-heading: 4 * $font-size;
$font-size-subheading: 2 * $font-size;
Or is there any other way to make this code better:
$font-size: 1.6rem;
$font-size-tab: 1.5rem;
$font-size-mobile: 1.4rem;
$font-size-heading: 4 * $font-size;
$font-size-subheading: 2 * $font-size;
$font-size-heading-tab: 4 * $font-size-tab;
$font-size-subheading-tab: 2 * $font-size-tab;
$font-size-heading-mobile: 4 * $font-size-mobile;
$font-size-subheading-mobile: 2 * $font-size-mobile;
For dynamic changing font sizes you could use the css clamp(min value, dynamic unit, max value) function.
[Kevin Powell did a nice Video on this][1]https://www.youtube.com/watch?v=U9VF-4euyRo
a sass way to further edit this function would be to set the fontsize with a clamp fuction and put in variables.
/*scss*/
#mixin dynamicFontSize ($a) {
font-size: clamp(10px * $a, 2vw * $a, 20px * $a);
}
#include dynamicFontSize (2);
/*or*/
#include dynamicFontSize (0.7);
for this soution you have to tinker a bit with the units but when you got it its awesome.

SCSS divide operator not compiling

I am using Sublime Text 2 and LiveReload to compile my .scss file. I also tried codekit with the same problem.
Using + and - work no problem, but * and / don't compile.
font-size: 30px / 2px; doesn't compile to font-size: 15px;
but
font-size: 30px + 2px; does compile to font-size: 32px;
Any ideas? The code hinting also doesn't seem to be working for the multiply and divide operators, could it be a package conflict? Seems unlikely.
Put it in parenthesis so SCSS understands you want it to do an arithmetic operation. Also, you do not want to divide px by another px number as this will result in a unitless number.
This is what you are looking for:
div {
font-size: (30px / 2)
}

Create em converter function in SASS not SCSS

I am new to SASS and Compass trying to create one function which can convert passed pixel value to em. I found one tutorial but it is for SCSS and that doesn't work with SASS.
Even I have checked on SASS website but seem they have most document for SCSS and not everything they have describe for SASS.
Here what I am writing
#function em($px, $base: 24px)
#return ($px / $base) * 1em
Also using vertical-rythem in my project and tried this to but than again giving error for $base-font-size
#function em($px, $base: $base-font-size)
#return ($px / $base) * 1em
So when I use it as
font-size: em(16px)
It should convert to 1em in output
The function you have seems correct. Just make sure you have defined $base-font-size with a value such as 16px.
The above mixin you have should also work
$base-font-size: 16px;
#function em($px, $base: $base-font-size) {
#return ($px / $base ) * 1em;
}
Now you can call font-size: em(16px); and it should work
You can also call this function with an optional base, sometimes you might want to calculate on a base that's not 16px.
Please also look up http://css-tricks.com/snippets/css/less-mixin-for-rem-font-sizing/ for rem font sizing. You might want to skip em because they have a nesting problem http://css-tricks.com/why-ems/
For a more detailed version of the above mixin, where you can call
border: emCalc (10 20 30 40);
Where you don't have to repeat the px value again and again and you may have 1 to 4 values within, check the mixin in Zurb's foundation _global.scss
https://github.com/zurb/foundation/blob/master/scss/foundation/components/_global.scss#L183

960gs Sass arguments

I'm currently in the process of learning 960gs using sass / compass, but I'm confused as to what the "$n" is in the following code and how to use the arguments.
$ninesixty-gutter-width: 20px !default
$ninesixty-grid-width: 960px !default
$ninesixty-columns: 12 !default
$ninesixty-class-separator: "_" !default
=grid-container
margin-left: auto
margin-right: auto
width: $ninesixty-grid-width
=grid-width($n, $cols: $ninesixty-columns, $gutter-width: $ninesixty-gutter-width)
width: $ninesixty-grid-width / $cols * $n - $gutter-width
According to the docs for that plugin...
"N is the number of grid columns to span as in grid_N or push_N with the original 960 Grid System framework."

Using a SASS variable as a value for CSS `content` property

Hi!
This might be caused by my lack of understanding of SASS/Compass.
I'm trying to output grid width with the following SASS code:
$total-columns : 4
$column-width : 4em // each column is 4em wide
$gutter-width : $column-width / 2 // 1em gutters between columns
$grid-padding : $gutter-width / 2 // grid-padding equal to gutters
#page
+container
+susy-grid-background
#block-block-3
div.content
p:first-of-type:after
content: columns-width()
Nothing is printed into block 3. :(
I also tried content: columns-width($total-columns), still nothing. If i do content: "foo", "foo" does get printed.
What am i doing wrong? How do i see susy-calculated grid width? Also, can it be printed in compass watch output?
Ok, the solution is using interpolation:
content: "#{columns-width($total-columns)}"

Resources