Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor with Sass #15

Open
JacobGrisham opened this issue Jun 30, 2021 · 1 comment
Open

Refactor with Sass #15

JacobGrisham opened this issue Jun 30, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@JacobGrisham
Copy link
Owner

JacobGrisham commented Jun 30, 2021

Remove the need for Bootstrap and practice Flexbox and Grid Layouts with Sass

Follow the styling guide from robinhood itself

@JacobGrisham JacobGrisham added the enhancement New feature or request label Jun 30, 2021
@JacobGrisham JacobGrisham self-assigned this Jun 30, 2021
@MADHUMITHASIVAKUMARR
Copy link

Refactoring your front-end styles to use Sass (Syntactically Awesome Style Sheets) can enhance your development workflow by allowing for better organization, variables, nesting, and mixins. Here’s a step-by-step guide to refactor your CSS to Sass for your finance full-stack web app.

Step 1: Install Sass

If you haven't already, you need to install Sass. You can do this via npm:

npm install sass --save-dev

Step 2: Set Up Your File Structure

Create a folder structure for your Sass files. A common setup might look like this:

/styles
  ├── /partials
  │   ├── _variables.scss
  │   ├── _mixins.scss
  │   ├── _base.scss
  │   ├── _layout.scss
  │   └── _components.scss
  ├── main.scss

Step 3: Create Partial Files

  1. Variables (_variables.scss):
    Define color schemes, fonts, and other constants.

    $primary-color: #3498db;
    $secondary-color: #2ecc71;
    $font-stack: 'Helvetica, sans-serif';
  2. Mixins (_mixins.scss):
    Create reusable styles.

    @mixin flex-center {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  3. Base Styles (_base.scss):
    Include your base styles for resets and typography.

    body {
      font-family: $font-stack;
      background-color: #f4f4f4;
      margin: 0;
      padding: 0;
    }
  4. Layout Styles (_layout.scss):
    Define styles related to the layout of your app.

    .container {
      width: 80%;
      margin: 0 auto;
    }
  5. Component Styles (_components.scss):
    Define styles for specific components.

    .button {
      background-color: $primary-color;
      color: white;
      padding: 10px 15px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    
      &:hover {
        background-color: $secondary-color;
      }
    }

Step 4: Main Sass File

In your main.scss file, import all the partials:

@import 'partials/variables';
@import 'partials/mixins';
@import 'partials/base';
@import 'partials/layout';
@import 'partials/components';

Step 5: Compile Sass to CSS

You can compile your Sass files to CSS using the command line:

npx sass styles/main.scss styles/main.css

You might also want to set up a watch command to automatically compile Sass files when changes are made:

npx sass --watch styles/main.scss styles/main.css

Step 6: Update HTML Links

Ensure that your HTML files link to the compiled CSS file:

<link rel="stylesheet" href="styles/main.css">

Step 7: Remove Old CSS

Once you’ve confirmed that everything works correctly with Sass, you can remove any old CSS files that are no longer needed.

Additional Tips

  • Nesting: Take advantage of Sass’s nesting feature to structure your CSS better. For example:

    .navbar {
      background-color: $primary-color;
    
      .nav-item {
        color: white;
    
        &:hover {
          text-decoration: underline;
        }
      }
    }
  • Use Functions: You can create custom functions in Sass for complex calculations or color manipulations.

  • Organize Further: As your project grows, consider breaking down your partials even further into more specific files for better organization.

Conclusion

Refactoring to Sass will make your stylesheets more maintainable and scalable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants