The 7-1 folder pattern helps keep your Sass files organized and easy to find. It splits styles into clear sections so you can work faster and avoid confusion.
7-1 folder pattern in depth in SASS
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
SASS
sass/ |- abstracts/ | |- _variables.scss // Sass variables | |- _mixins.scss // Sass mixins | |- _functions.scss // Sass functions |- base/ | |- _reset.scss // Reset/normalize styles | |- _typography.scss // Typography rules | |- _base.scss // Base styles |- components/ | |- _buttons.scss // Buttons | |- _carousel.scss // Carousel | |- _modal.scss // Modal |- layout/ | |- _header.scss // Header | |- _footer.scss // Footer | |- _sidebar.scss // Sidebar | |- _grid.scss // Grid system |- pages/ | |- _home.scss // Home page styles | |- _about.scss // About page styles |- themes/ | |- _theme.scss // Theme styles |- vendors/ | |- _bootstrap.scss // Bootstrap overrides |- main.scss // Main Sass file that imports all others
The folder names describe what kind of styles go inside.
Each folder has partial Sass files starting with an underscore (_).
Examples
SASS
@import 'abstracts/variables'; @import 'base/reset'; @import 'components/buttons';
SASS
// abstracts/_variables.scss $primary-color: #3498db; $font-stack: 'Helvetica Neue', sans-serif;
SASS
// components/_buttons.scss .button { background-color: $primary-color; font-family: $font-stack; padding: 1rem 2rem; border: none; border-radius: 0.5rem; }
Sample Program
This HTML uses styles compiled from Sass files organized with the 7-1 pattern. The button uses variables and mixins from abstracts, and layout styles come from layout folder.
SASS
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>7-1 Folder Pattern Example</title> <link rel="stylesheet" href="css/main.css" /> </head> <body> <header class="site-header"> <h1>Welcome to My Site</h1> </header> <main> <button class="button">Click Me</button> </main> <footer class="site-footer"> <p>© 2024 My Site</p> </footer> </body> </html>
Important Notes
Always keep your main.scss clean by only importing partials.
Use clear folder names to help everyone understand your style structure.
Partial files start with an underscore (_) and are not compiled alone.
Summary
The 7-1 folder pattern organizes Sass files into 7 folders plus 1 main file.
This helps keep styles easy to find and maintain.
Use partial files and import them into main.scss for a clean workflow.
Practice
1. What is the main purpose of the 7-1 folder pattern in Sass?
easy
Solution
Step 1: Understand the folder pattern concept
The 7-1 pattern divides Sass files into 7 specific folders and 1 main file to keep code organized.Step 2: Identify the main goal of this structure
This organization helps developers find and maintain styles easily, improving workflow.Final Answer:
To organize Sass files into 7 folders plus 1 main file for better structure -> Option BQuick Check:
7-1 pattern = organized folders + main file [OK]
Hint: Remember 7 folders + 1 main file = organized Sass [OK]
Common Mistakes:
- Thinking it compresses CSS automatically
- Believing it creates themes without extra code
- Confusing it with CSS frameworks
2. Which of the following is the correct way to import a partial file named
_buttons.scss into main.scss using the 7-1 pattern?easy
Solution
Step 1: Recall Sass partial import syntax
Partial files start with an underscore and are imported without the underscore or file extension.Step 2: Apply correct import syntax
So,_buttons.scssis imported as@import 'buttons';inmain.scss.Final Answer:
@import 'buttons'; -> Option AQuick Check:
Import partials without underscore or extension [OK]
Hint: Drop underscore and .scss when importing partials [OK]
Common Mistakes:
- Including underscore in import statement
- Adding .scss extension in import
- Using folder path incorrectly
3. Given this folder structure in the 7-1 pattern:
What will happen if
and you compile
sass/
├── abstracts/_variables.scss
├── base/_reset.scss
├── components/_buttons.scss
└── main.scssWhat will happen if
main.scss contains:@import 'abstracts/variables';
@import 'base/reset';
@import 'components/buttons';and you compile
main.scss?medium
Solution
Step 1: Understand how imports work in Sass
When you import partials inmain.scss, their styles are combined into one CSS output.Step 2: Analyze the import paths
Using folder names likeabstracts/variablesis valid and imports the partial correctly.Final Answer:
All styles from variables, reset, and buttons partials will be combined into one CSS file -> Option AQuick Check:
Imports merge partials into one CSS [OK]
Hint: Imports combine partials into one CSS file [OK]
Common Mistakes:
- Thinking imports create separate CSS files
- Believing folder names are invalid in imports
- Assuming imports are ignored during compilation
4. You have this import in
But when compiling, you get an error:
What is the most likely cause?
main.scss:@import 'layout/grid';But when compiling, you get an error:
File to import not found or unreadable: layout/_grid.scss.What is the most likely cause?
medium
Solution
Step 1: Check the error message
The error says the filelayout/_grid.scsscannot be found or read.Step 2: Understand import rules
Importing@import 'layout/grid';expects a file named_grid.scssinside thelayoutfolder.Final Answer:
The file _grid.scss is missing from the layout folder -> Option DQuick Check:
Missing partial file causes import error [OK]
Hint: Check if partial file exists in correct folder [OK]
Common Mistakes:
- Including underscore and extension in import
- Moving main.scss into partial folders
- Assuming Sass disallows folder nesting
5. In the 7-1 folder pattern, you want to add a new component style for a card UI element. Where should you place the partial file and how should you import it in
main.scss?hard
Solution
Step 1: Identify the correct folder for UI components
The 7-1 pattern uses thecomponentsfolder for UI parts like buttons, cards, and modals.Step 2: Use proper import syntax in main.scss
Place_card.scssinsidecomponentsand import as@import 'components/card';.Final Answer:
Place _card.scss in components folder and import with @import 'components/card'; -> Option CQuick Check:
UI parts go in components folder [OK]
Hint: Put UI parts in components folder, import with folder/name [OK]
Common Mistakes:
- Putting components in base or abstracts folders
- Importing with underscore or .scss extension
- Placing partials outside organized folders
