I have a main.css:
#import '~bootstrap/less/bootstrap.less';
#import url('./base.css');
#import url('./components/navbar.css');
I want to override bootstrap's default body background-color, so I have
body {
background-color: #efefef;
}
inside base.css,
but that does not override bootstrap's property. If I import ~bootstrap/dist/css/bootstrap.min.css instead of ~bootstrap/less/bootstrap.less, I am able to see my changes, but not with less file. How can I achieve that?
That's because you cannot import a .less file in a .css file. it has to be converted first.
If you want to import the .less file, you'd have to have a main.less and convert that to .css
You can use GRUNTJS for that.
Related
Is it possible to load property from class from different scss file? This side scss file is imported to main scss file. All properties are inherited, but margins, paddings, font styles not. Browser is not willing to load these properites. Are there any rules with extend?
Side scss file:
.section-headline {
font-size: em(30);
font-weight: 700;
line-height: auto;
color: $main-col-text;
margin-bottom: em(20);
}
Main scss file:
.i-headline {
#extend .section-headline;
}
In SASS you can declare classes in one file and import them into another without any problem, just make sure your import is done properly. And yes you can use #extend to access the rules of your imported selector.
Also try display: inline-block; and see if your margin/padding are working. Maybe you were trying to apply them to an inline element.
Does your em() function is imported somewhere ?
I found the problem. I have one scss file where are imported all scss sub-files. It looks like this:
#import 'gClass';
#import 'buttons';
#import 'general';
#import 'mixins';
#import 'typography';
#import 'pages/home';
In sub-file gClass is my class .section-headline. In pages/home is scss code with i-headline class. I tried to copy .section-headline to main scss file mentioned upper. In this case it works, but if i try to have .section-headline in gClass file, it doesnt.
Have an issue where a css framework imported into a scss file is clobbering the styles of the wysiwyg editor. Is there a way to import the framework and have it "skip" any element within a class or ID?
I've tried.. to no avail...
// app.scss file
body :not(#wysiwyg) {
#import 'node_modules/some_css_framework.scss';
}
// also tried..
body *:not(#wysiwyg) {
#import 'node_modules/some_css_framework.scss';
}
(Everything except for the #wysiwyg element, import and apply these styles..
In Angular 2, I have a CSS class in my styles.scss file:
.FirstClass {
}
I'm trying to extend this class in a component's .SCSS file (eg.: MyComponent.scss) like:
.SecondClass {
#extend .FirstClass;
}
I'm getting an error that says .FirstClass is not found. Do I assume correctly that class and style in styles.scss can be globally referred? Please help me in this.
If you have any file, and you want to use one of its classes in another file, you have to import it first.
styles.scss
.FirstClass{}
MyComponent.scss
#import 'styles.scss'
.SecondClass{
#extend .FirstClass;
}
SCSS is compile to CSS, hence, if you need to make any changes in the file itself that not related plain css, you have to take it into consideration.
I have a style library with the general styling for my project. This library is packed into one library.css file. In this library, I have a class a.
In one of my scss stylesheets I'd like to extend this calss a from library.css:
#import 'library.css';
.b {
#extend .a
}
When I do this, I'm told that class a was not found in library.css.
Is there any way to extend a class from a CSS stylesheet?
When you add an #import at-rule to your Sass code, you need to be careful what you wish to achieve. #import is actually valid CSS, so Sass needs to evaluate and figure out your intentions here. Sass extends the CSS #import rule and does not recreate it. According to the documentation:
#import takes a filename to import. By default, it looks for a Sass file to import directly, but there are a few circumstances under which it will compile to a CSS #import rule:
If the file's extension is .css.
If the filename begins with http://.
If the filename is a url().
If the #import has any media queries.
As a result, if you put the .css extension after the filename in an #import at-rule, Sass will just output this line of valid CSS code. You can test this by removing your #extend directive, which will make your code compile. You will see that the entire output file is this:
#import 'library.css';
Sass is not going to follow that CSS file and make it's contents available to the #extend directive.
What you could do is remove the file extension from your #import at-rule.
#import 'library';
.b {
#extend .a
}
However, this will actually output the entire contents of the file library.css into your CSS file that this Sass file compiles to, which I am assuming is not your goal.
To fix that, you could create a partial Sass file that contains placeholder selectors.
%a {
color: red;
}
The good thing about placeholder selectors is that they have no output of their own. According to the documentation:
On their own, without any use of #extend, rulesets that use placeholder selectors will not be rendered to CSS.
Their importance and usefulness is detailed on this page.
Import the partial Sass file in your Sass stylesheet and use the #extend directive like this:
.b {
#extend %a;
}
And to make sure your library.css file is consistent, convert it into Sass, import the same partial file on top of it containing your placeholder selectors and simply use the #extend directive inside .a selector as well.
#import 'placeholders';
.a {
#extend %a;
}
I would like to use sass in my new project, but I can't find a better way for cross file usage. Here is the example
/*a.scss*/
#mixin mixA{
....
}
.classInA{
...
}
/*b.scss*/
#import 'a'
....
I want to use the mixA without having other scss(such as classInA) being imported into b.scss, how can I do it?
One way to do it is to put all your mixins in a general mixins file, then, import that file into another general file where you import all the SCSS (or SASS) files.
/*mixins.scss*/
//Here goes all your mixins
/*main.scss*/
#import 'mixins';
#import 'header';
#import 'footer';
And import the mixins you want in the files needed.
If you want to import other sass file simply do :
#import 'path/sass-file';
#import 'path/sass-file';
#import 'path/sass-file';
If you would like extend any of already created class in your scss you can do it like this :
.new-custom-class {
#extend .custom-class;
/* you can add some options in here also */
}