I am using sass and compass for my project. However it provides a very cool mixins for i.e hacks.
For eg:
.display { #include inline-block; }
will execute
.display { display: -moz-inline-stack;
display: inline-block;
vertical-align: middle;
*vertical-align: auto;
zoom: 1;
*display: inline;
}
But I want to separate all the ie hacks code to different css file such as ie.css and want it to place inside ie conditional comments, so that my css file would be w3c compatible.
Is there any idea to overcome this problem.. Any help will be greatly appreciated. Thanks in advance.
Just create two "parent" sass files. e.g. screen.scss & ie.scss
Put all of your actual sass into separate "child" scss files.
Then in your "parent" files only have import statements.
EXAMPLE:
SCREEN.SCSS
//Global
#import "vars";
#import "mixins";
//Base
#import "reset";
#import "base";
#import "layout";
//MODULES
#import "modules/module_a";
#import "modules/module_b";
IE.SCSS
#import "vars";
#import "mixins";
#import "ie_hacks";
This lets you import all of the sass dependant "child" files like any variable or mixins. It also lets you keep all the ie stuff in a separate css file. ie.scss is obviously going to be markedly smaller than your main screen.scss
Related
I've got a mechanism that uses one of the following 3 files, depending on what UI mode (light, dim or dark) is selected. There are only SCSS variables defined in those files.
_variables_light.scss
$primaryColor: red;
_variables_dim.scss
$primaryColor: blue;
_variables_dark.scss
$primaryColor: black;
Now I've got the following file which should work regardless of which UI mode is selected.
_styles.scss
.navMenu {
background: $primaryColor;
}
I used to solve this using the following file (example for light mode) which would then be compiled to CSS.
light.scss
#import 'variables_light';
#import 'styles';
I want to replace #import by #use as the former is deprecated but the only way I could make it work is
#use 'variables_light';
#import 'styles';
Now if _styles.scss contains #import statements again, the variables from variables_light can not be used everywhere. Is it even possible to use #use over several layers of imports?
I've set up my project to use Bootstrap and scss with Webpacker, however, whenever I start my server locally I get this error:
ActionView::Template::Error (Error: Undefined variable: "$secondary-accent".
on line 76:23 of app/assets/stylesheets/_hero.scss
>> border: solid 0.5px $secondary-accent;
This error actually goes away locally if I do a hard refresh, but of course, Capistrano is not as forgiving and I want to figure out the issue anyway.
In my /app/javascscript/ folder I have a src/style.scss file which imports the required stylesheets.
#import '../../assets/stylesheets/_globals.scss'; //import globals first so the values propagate to Bootstrap
#import '~bootstrap/scss/bootstrap'; //import bootstrap
#import '../../assets/stylesheets/application.scss' //import everything else;
/assets/stylesheets/application.scss looks like:
#import '_navbar';
#import 'actiontext';
#import '_hero';
#import 'comments';
#import 'static_pages';
body {
font-family: $body-font;
font-size: $standard;
}
Of course, the easy way to get rid of this is to just add #import 'globals' to each of the partials but that does not seem to fit with the sass way. I don't really want to add #import 'globals' at the top of every single .scss file, not a big deal at the moment but as the project grows and the complexity of the styles increases maintainability could become a headache. I thought that Webpacker would take care of this, am I wrong? Am I missing something in the setup?
Ps. I realize this question has been asked dozens of times, but they all seem to be for older versions of Rails, or the solutions don't apply to me (such as removing the require tree from application.css
This was resolved by tightening my Webpacker set up a bit.
The biggest issue was installing scss I thought sass-rails in my gemfile was sufficient but I also needed yarn add scss. I didn't need to import the globals inside of src/style.scss just in application.scss.
I would like to know how can i extend default gap between columns in bulma, according official website is-8 gap equals 2em but i need 6em,can i override $column-gap value in my css file ?
This is a Sass variable, you can override it but not in a .css file, your need to setup Sass with node-sass or with Sass CLI or with webpack, you can also learn more about customisation with sass variables here.
All those links point to the official documentation and will help you with the setup. Then you will be able to overrride the value of the $column-gap and all other sass variables in a .scss file like this :
#charset "utf-8";
// Update all the variables you want :
$column-gap: 6em;
// And then import bulma
#import "../path/to/bulma";
// Or import only what you need from Bulma
#import "../path/to/bulma/sass/utilities/_all.sass";
#import "../path/to/bulma/sass/base/_all.sass";
#import "../path/to/bulma/sass/elements/container.sass";
#import "../path/to/bulma/sass/elements/title.sass";
#import "../path/to/bulma/sass/form/_all.sass";
#import "../path/to/bulma/sass/components/navbar.sass";
#import "../path/to/bulma/sass/layout/section.sass";
We need to put #import at the end of my CSS file. For example:
SCSS:
#import "reset.css";
Body {
font: 0.8em arial;
}
#import "customation.css"
compile to:
#import "reset.css";body{font: 0.8em arial;}#import "customation.css"
but after compile it changed the #import order and CSS file will be this:
#import "reset.css";#import "customation.css";body{font: 0.8em arial;}
It's very important for us to keep #importing the custom.css file at the end for our customization. We can't put the #import to CSS file manually because SCSS file will be changed and CSS file will be rewritten.
Any suggestion?
You can't. Sass is smart enough to know that #import declarations must be at the beginning of the file so it rewrites it for you to be valid.
The #import CSS at-rule allows to import style rules from other style sheets. These rules must precede all other types of rules, except #charset rules; as it is not a nested statement, it cannot be used inside conditional group at-rules.
https://developer.mozilla.org/en-US/docs/Web/CSS/#import
If this is not acceptable, you'll need to use multiple link declarations (which are arguably better anyway for the user).
Are you using #import for any particular reason? There are performance impacts, and no major use case anymore.
It would be better if you used Sass's #import to concatenate the file instead, this would also allow you to import in the order you want and rely on the cascade.
#import "reset";
Body {
font: 0.8em arial;
}
#import "customation";
It seems like my scss is turning off ordered list styles by default, which seems a little strange / annoying. Can anyone explain why it would do that?
This is the line that was mysteriously added to my css:
/* line 24, C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
ol, ul {
list-style: none;
}
A little splunking showed that was the result of these lines in the _utilities.scss file:
ol, ul {
#include reset-list-style; }
// Reset the list style of an element.
#mixin reset-list-style {
list-style: none; }
I'm fixing this issue by adding:
ol {
list-style-type: decimal;
}
to my scss file. Would it be better to modify the _utilities.scss file? It sounds like if I did that it might screw up how scss translates into css for ol, ul elements?
If you don't like this behavior, you can take out the reset that's included with Compass. When you start a new compass project, it generates screen.scss with the following:
/* Welcome to Compass.
* In this file you should write your main styles. (or centralize your imports)
* Import this file using the following HTML or equivalent:
* <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
#import "compass/reset";
Just remove or comment out the #import "compass/reset" and use a reset that's to your liking or use something like normalize.css to standardize styles.
Yes, Compass (as bootstrap) resets the list-style for lists as written here
compass utilities documentation
I think the best practice would be to add the "inverse" reset rule just to your stylesheet, instead of modifying the library, because, in case you are going to change (maybe) the version of your library and forget to patch it again, you will find unexplainable "errors". I would add it to my reset rules.