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.
Related
I'm doing media queries in a seperate scss file named _media.scss, so I can seperate my main style.scss file from the media queries to make things easier to manage.
However it seems that because i import the _media.scss file at the top of the style.scss file then because of the nature of the cascading rules, the style.scss rules are overriding the _media rules as they come after the import.
To get the _media rules to take priority i'm having to add on !important to a lot of rules. I tried cutting and pasting all the media queries to the bottom of the style.scss file and it works without the !important flag.
Is there any way to give the _media partial priority over the style file so I fix this?
Code:
Inside the style.scss file:
#import 'config';
#import 'utilities';
#import 'form';
#import 'dropdown';
#import 'animations';
#import 'media';
.logo {
font-size: 2em;
}
Inside the _media.scss:
#media(max-width: 500px) {
.logo {
font-size: 1.5em;
}
}
Inside the chrome dev tools, i've got the same classes as above with font-size: 1.5em crossed out.
Not sure why 2em is taking priority?
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 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.
I'm using Google Fonts, and have imported it in less. Here is my code:
main.less
#container {
#import url(http://fonts.googleapis.com/css?family=Raleway:300);
.like {
font-family: 'Raleway', sans-serif;
}
}
This doesn't work. but if I put #import url(http://fonts.googleapis.com/css?family=Raleway:300); before #container, it does.
I'm guessing this maybe because of path, but I don't know why. How do I fix this?
"Your #imports must come before all other content in your CSS. And I mean all of your content. Even putting comments before the #import tag will cause your imports to fail. So be sure to do your imports before you do anything else." - http://www.cssnewbie.com/css-import-rule/#.UtNj1PQmnn8
Direct from W3C:
"Any #import rules must precede all other at-rules and style rules in a style sheet (besides #charset, which must be the first thing in the style sheet if it exists), or else the #import rule is invalid." - http://www.w3.org/TR/css3-cascade/#at-import
Here's a fiddle: http://jsfiddle.net/setek/5QsvU/
This demonstrates that when #import is not the first line of a stylesheet/embed, it does not work. Try putting the #import first line, you can see what happens:
#sidebar a { color: #f00; }
#import url('http://jsfiddle.net/css/screen.css?jobofferinsidebar');
vs. just having:
#import url('http://jsfiddle.net/css/screen.css?jobofferinsidebar');
Hello I am trying to use SASS in a project, but have come across a problem and I was wondering if anyone could help?
I have created two style sheets. One called defaults.scss and one called styles.scss. In the defaults.scss I have declared the following:
$mainColor: #848484;
I then try to call the $mainColor in my styles.scss using the following:
nav ul {
list-style: none outside none;
margin: 0; font-size: 1.2em;
color: $mainColor;
padding: 50px 0 0 0;
font-weight: bold;
text-align: center;
}
But I get the following error message: Syntax error: Undefined variable: "$mainColor".
Can anyone see what I am doing wrong? I have compass running.
Thanks.
If understand correctly, you have two .scss files. What I normally do is have a styles.scss and in that file you import all of the other .scss style sheets. I think they call them partials or something. So that your main style.scss compiles all of the .scss files together into the .css file. Right now I don't think your two files are aware of each other. your main styles.scss should simply look like this:
#import "reset.scss";
#import "global.scss";
#import "structure.scss";
#import "colors.scss";
#import "etc.scss";
Make sure they are in your intended cascading order - because that is how they will be smushed together. In your case, default first and then main.
It gets tricky when you start adding media queries too - but this should fix you up I think.
In your html you just need to call your .css file that the whole operation outputs.
<link rel="stylesheet" href="css/style.css"> or wherever you have it going to. Just one.