Variables in imported scss files generate error in Scout's log - compass-sass

Below is my main scss file for my current project.
I use the variables also in css_ve.scss which is imported afterwards.
The generated css files work as expected but Scout throws errors in the log panel because it can't find the variables declarations in css_ve.scss.
This is a minor issue but I would like to know how to prevent these errors from occuring.
One solution would be to create a scss file only for variables and import it from all the other files but I would like to avoid to have too many scss files scattered in my project.
Thanks in advance!
/* VARIABLES ------------------------------ */
/* fonts */
$font-family-1: 'Arial', 'Meiryo', 'MS Gothic', 'MS UI Gothic', 'MS PGothic', 'Arial Unicode';
$font-family-2: 'MS UI Gothic', 'MS PGothic', 'Arial Unicode';
$font-size: 14px;
/* colors */
$color-1: #000000; /* black */
$color-2: #ffffff; /* white */
$color-3: #CCCCCC; /* grey */
$color-4: #00A3AF; /* green */
$color-5: #FF6600; /* orange */
/* IMPORTS ------------------------------ */
/* validationEngine */
#import "validation_engine/css_ve.scss";
/* STYLES ------------------------------ */
....

#import "validation_engine/css_ve"; perhaps?

Related

How to override .alert-[style] in Bootstrap 4?

I'm just starting with Bootstrap 4 and Sass. I can't for the life of me figure out how to override the default .alert-[whatever] styles.
If I have:
<div class="alert alert-success">Hello!</div>
It creates an alert with the default light shade of green that ships with Bootstrap 4. The only way I can override it is with my own custom CSS style for .alert-success. I'd rather use a built in variable to override it like I'm doing with my other colors, but I have no idea if that's an option?
In my .scss file I have:
$blue: #3498db;
$green: #37bf91;
$theme-colors: (
"primary": $blue,
"success": $green,
);
I assumed that .alert-success would just use the $green I've specified in my .scss file, but that doesn't seem to be the case.
I've tried to do $alert-success: $green;which also doesn't change anything.
What's the correct way to go about this?
This is similar to: How to change the bootstrap primary color? Make sure you import Bootstrap after the overrides, and I will answer as it related to alerts.
/* custom.scss */
/* import the necessary Bootstrap files */
#import "bootstrap/functions";
#import "bootstrap/variables";
/* -------begin customization-------- */
$blue: #3498db;
$green: #37bf91;
$theme-colors: (
primary: $blue,
success: $green,
);
/* -------end customization-------- */
/* finally, import Bootstrap to set the changes! */
#import "bootstrap";
Demo: https://www.codeply.com/go/NCfqvU3Upe
For the alerts, the bg and text colors are derived using the SASS darken function on the theme color. The defaults are:
$alert-bg-level: -10 !default;
$alert-border-level: -9 !default;
$alert-color-level: 6 !default;
The negative numbers lighten the original theme color, the positive numbers darken the color. So, for example if you want to make the success alert bg closer to the actual $green color, you'd adjust the alert variables:
$alert-bg-level:0; // this negates the darken function
$alert-border-level:1;
$alert-color-level:-10;
I updated the demo to show this.

Iterate over theme-variable files in SCSS

I want to create different css-themes for a WordPress theme by using theme setup files. The setup (simplified) would be as following:
/themes/_theme1.scss
/themes/_theme2.scss
/components/_file1.scss
/components/_file2.scss
/theme.scss
The idea is to enable easy theming by adding a class to the body of the document like .theme-theme1 or .theme-theme2. In the files _theme#.scss I want to define variables like text colour, font sizes and so on. In _file#.scss the actual styles are defined.
My question now is, how to iterate over the theme setup files while filling up the files.scss.
Sample idea, Background colour:
body {
###foreach themefile###
&.theme# {
background-color: $background-color;
}
###/foreach###
}
I know how to do this with only one theme available in the resulting CSS file, but I want to make ALL themes available in the resulting CSS. Feel free to ask more details as I am not sure if I explain me right.
Is there a way to create this stylesheet via some kind of foreach loops through variables in theme files or does it have to be done with extra scss-rules per theme file?
This is somewhat possible using a combo of #import with a #mixin to generate the styles. This method should produce minimal repeated code.
Here's how we'll setup the files.
- scss
- themes
- _theme1.scss
- _theme2.scss
- _theme.scss
- styles.scss
The _ prefix on some of the files prevent them from being compiled into CSS to keep our build nice and clean. Now let's go through the contents of the files:
_theme1.scss
$theme-name: 'theme1';
$primary-color: red;
$primary-font-size: 24px;
_theme2.scss
$theme-name: 'theme2';
$primary-color: blue;
$primary-font-size: 12px;
This is an oversimplified example but should give the basic idea. Each theme file will contain only variables.
_theme.scss
#mixin themestyle() {
body.#{$theme-name} {
p {
color: $primary-color;
font-size: $primary-font-size;
}
.bordered {
border: 3px solid $primary-color;
}
}
}
The themestyle mixin will contain all the styles for each theme, using the variables from the /themes/_theme*.scss files. The body.#{$theme-name} will create a selector like body.theme1 or body.theme2, depending on the current value of the $theme-name variable.
In this demo I'm styling on a p tag but this could easily be extended to all elements/selectors for your site. The important thing to remember is all styles need to be inside the body.#{$theme-name} selector.
Now the final, and least DRY part. The styles.scss file will import each theme file then call the themestyle mixin to generate the styles for each theme.
styles.scss
#import 'themes/theme';
/* Theme 1 Styles */
#import 'themes/theme1';
#include themestyles();
/* Theme 2 Styles */
#import 'themes/theme2';
#include themestyles();
The repeated #import/#include is required because it's not possible to #import within a loop or mixin, or this could be optimized a bit more.
Once styles.scss is compiled the output will be:
/* Theme 1 Styles */
body.theme1 p {
color: red;
font-size: 24px; }
body.theme1 .bordered {
border: 3px solid red; }
/* Theme 2 Styles */
body.theme2 p {
color: blue;
font-size: 12px; }
body.theme2 .bordered {
border: 3px solid blue; }
These themes can now be implemented by adding a class to the body tag, like <body class="theme1"> or <body class="theme1">.
Here's a Cloud9 project showing the setup.

Include `.scss` file in another `.scss` file?

How can I Include .scss file in another .scss file?
I was trying to write this in a file:
app.scss:
#include('buttons');
#include('dropzone');
body {
background: $primaryColor;
overflow-x: hidden; /*Clip the left/right edges of the content inside the <div> element - if it overflows the element's content area: */
height: 100%; /* Cover all (100%) of the container for the body with its content */
padding-top: 70px;
} /* more css code here */
and it returns an error : invalid css after #import
I try to include 2 other scss files inside the main scss file, so it will be all compiled to one css file eventually. How is it possible?
You can import it like this;
#import "../../_variables";
#import "../_mixins";
#import "_main";
#import "_login";
#import "_exception";
#import "_utils";
#import "_dashboard";
#import "_landing";
According to your directories and it will do what you want.
You can include a partial by doing this:
#import "partial";
The imported file needs an underscore, so sass will recognize it to be included: _partial.scss
You can use #use rule for it. This rule loads another Sass file as a module, which means you can refer to its variables, mixins, and functions in your Sass file with a namespace based on the filename. Using a file will also include the CSS it generates in your compiled output!
// _base.scss
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
see how to using #use 'base'; in the styles.scss file
// styles.scss
#use 'base';
.inverse {
background-color: base.$primary-color;
color: white;
}
you don't need to include the file extension.
#osherdo You have no need to add !important for overwriting bootstrap CSS.
body
{
background: #4d94ff; /* Use to override Bootstrap css settings. */
}
First of you need to verify from where bootstrap is rendering on the page and what is the weight of the bootstrap CSS file. After that you can place your 'css/app.css' file after bootstrap then it will work. Then you can easily overwrite the entire bootstrap CSS.
Ok, so it appears to be that my app.scss file collide with Bootstrap.css file.
Because I wanted the app.scss background property to apply, instead of the bootstrap css file. I've added !important in this property to override bootstrap style.:
body
{
background: #4d94ff !important; /* Used to override Bootstrap css settings. */
}
Also, gulpfile.js has been updated to suite my needs accordingly:
var elixir = require('laravel-elixir');
elixir(function (mix) {
mix.sass('app.scss', 'resources/assets/css')
.styles([
'app.css'
], 'public/css/app.css');
mix.version([
'css/app.css'
]);
});
And that's how I fixed it.

SASS syntax error: Undefined variable: "$em-base"

I'm following a new SASS structure guide here.
Trying to use the PX to EM mixin and seems like the variable isn't getting through.
But I have the base importing the mixins and the typography is imported last.
Main SASS file:
// Modules and Variables
#import "modules/base";
// Partials
#import "partials/normalize";
#import "partials/typography";
BASE.scss:
#import "colors";
#import "fonts";
#import "animation";
#import "mixins";
_mixins.scss:
/* PIXELS to EM */
// eg. for a relational value of 12px write em(12) when the parent is 16px
// if the parent is another value say 24px write em(12, 24)
// #include em(12);
#function em($pxval, $base: $em-base) {
#if not unitless($pxval) {
$pxval: strip-units($pxval);
}
#if not unitless($base) {
$base: strip-units($base);
}
#return ($pxval / $base) * 1em;
}
And finally _typography.scss:
// widget table headers
section header h1 {
font-family: LatoRegular;
font-size: em(18);
}
Error from CodeKit:
Syntax error: Undefined variable: "$em-base".
on line 6 of /assets/sass/partials/_typography.scss
from line 38 of /assets/sass/dashboard.scss
$em-base is not defined in any of your files.

avoid duplication using placeholder selectors in Sass 3.2

The problem is that my Sass code is generating duplicate declarations in the compiled CSS file.
My Sass code is organized in multiple partials, and I #import them into a final screen.scss file
I have a _placeholders.scss which contains %alignright and %alignleft.
I have a _content.scss file which uses these, so I #import "_placeholder.scss" at the top of that file and I do the same in _footer.scss. So I guess #import "_placeholders.scss" in 2 places is causing the duplication?
If I just #import "_placeholders.scss" at the beginning of screen.scss to make them globally accessible, then it messes with the order of the CSS declarations.
The first CSS selector to use a placeholder selector will be inserted at the order where I #import "_placeholders.scss", instead of where I #import "_conntent.scss".
For example, in screen.scss:
#import "placeholders";
#import "reset";
#import "typography"
#import "content" // uses placeholder %alignleft
#import "footer" // uses placeholder alignleft
Generated CSS:
/* Content styles that use placeholders */
/* reset styles */
/* typography styles */
/* expected order of content styles */
/* footer styles */
How do I avoid duplication and get the styles to be output in the correct place in the compiled CSS?
This is a place where you'd need to #include a #mixin rather than #extending a placeholder.
// in _placeholders.scss
#mixin alignleft {
text-align: left;
}
// in _content.scss
div.whatever {
#include alignleft;
}
// in _footer.scss
div.whatever-footer {
#include alignleft;
}

Resources