Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML Build a Blog with Jekyll and GitHub Pages Hosting with GitHub Pages Publishing a New Post

jack duong
PLUS
jack duong
Courses Plus Student 100 Points

How do I import custom css file into main.scss? I can't get it to work.

I created a 'layout' folder under _sass, and made a new file called '_index'.scss.
In the index file I change the background-color for body to black. Then in the main.scss I put @import "layout/index". When I start the server, the background color doesn't change , and I don't get any error messages either.

Anupam Majhi
Anupam Majhi
5,826 Points

Can you please share your workspace?

Hmm.. this could be a specificity issue. Are you changing background color for body anywhere in your main.scss file. It could be overriding _index.scss body rule.

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

Try using:

_index.scss
body {
  background-color: #000 !important;
}

...to see if that makes any difference. If so, then you're defining the background-color to be something else, later on in the styles.

Also, If your main.scss file is located at "http://www.yoursite.com/css/main.scss", and is compiled to create "http://www.yoursite.com/css/main.css", including @import "layout/_index.scss", then it would be looking for "http://www.yoursite.com/css/layout/_index.scss".

I would recommend keeping all .scss files in one directory for a less confusing structure (at the beginning, at least.) So you can have "http://www.yoursite.com/css/main.scss", which will easily be configured to use:

main.scss
@import "_reset.scss";
@import "_index.scss";
@import "_theme.scss";

...so the directory listing would be:

_reset.scss
_index.scss
_theme.scss
main.css
main.scss

If _index.scss had the body's background-color set to #000, and _theme.scss had it set to #fff, then the background-color would be defined as #fff since that "cascaded" over the previous value. !important would force the first value to take precedence, overwriting whatever followed it (unless that was defined as !important, as well.)

EDIT: Sorry for any spelling mistakes. Autocorrect was being evil.

Did you check the spelling? Did you intend main.scss or main.sass?

1 Answer

jack duong
PLUS
jack duong
Courses Plus Student 100 Points

Thanks everyone! I took Stevens advice, and setup my css files in one directory and it worked lol. So I basically linked it to the wrong location. Can't believe the amount of time I spent on this. Thanks for the help!