JacobGrisham / Finance-Full-Stack-Web-App-using-Flask-and-SQL

Monolithic model-view-controller full-stack web application built with Python, Flask, SQL Alchemy, MySQL, Jinja, and Bootstrap. Application Server hosted on AWS EC2 with Ubuntu, Gunicorn, and Nginx. MySQL Database on AWS RDS. Redis hosted on AWS Elasticache. CI/CD with Jenkins and AWS CodeDeploy
http://wallstreettrader.app
15 stars 28 forks source link

Refactor with Sass #15

Open JacobGrisham opened 3 years ago

JacobGrisham commented 3 years ago

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

Follow the styling guide from robinhood itself

MADHUMITHASIVAKUMARR commented 1 month ago

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

Conclusion

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