Skip to content
  • iImagine
  • Register
  • Log In

Web Development School

Learning made easy.

  • Books
    • Beginning Web Development with ASP.Net Core & Client-Side Technologies
      • TOC
      • Part 1
        • Chapter 1: Static HTML – Designing the landing page
      • Part 2
        • Chapter 2: ASP.Net Core – Let’s talk Dynamic
        • Chapter 3: Introduction to ASP.Net Core MVC
          [ASP.Net Core v9]
      • Part 4
        • Chapter 7: Using Server Side & Client Side technologies together
          [ASP.Net Core v7 & Angular 15]
  • Environment Setup
    • Installing Angular
    • Installing Visual Studio 2022
    • Installing SQL Server 2022 Express
    • Installing Postman
    • Installing Git for Windows
  • Blog
  • iImagine WebSolutions
  • Events
  • Learning Videos
  • Toggle search form

Configuring for Saas: CSS with superpowers

We first starting using CSS back in chapter one, “Static HTML – Designing the landing page”. CSS is a great tool for taking control of the appearance of HTML elements and our web application. But it does have it’s limitations and can force us to repeat a lot of code making our code WET (Write Everything Twice) rather then DRY (Do Not Repeat Yourself).

Sass is a CSS extension language. It makes CSS more dynamic by allowing us to create variables, use nesting, and utilize looping, among other features. In the same way dynamic frameworks like ASP.Net Core and Angular can turn our static HTML into full fledge web applications, and TypeScript makes JavaScript easier to work with classes and strongly typed variables and objects, Sass acts as a superset of CSS.

Saas is a superset of CSS just as TypeScript is a superset of JavaScript. Any valid CSS file is also a valid Saas file. So you can learn as you go and extend your CSS files at your own pace.

In the next section we are going to configure our application to use Saas.

Note: At this point I am copying the project from the Module13 folder to a Module14 folder. The pathway I am using for development here is:
C:\Development\FredsCars\FullStack\Module14.
Table Of Contents
  1. Configure Angular for Saas
    • Angular Schematics
    • Global Stylesheet
    • Update existing components
      • Update filename extensions
      • Update component style references
  2. Test Saas
  3. What's Next

Configure Angular for Saas

Let’s quickly go through the steps to enable the use of Saas in our FredsCars Angular application.

Angular Schematics

Right now when we create a component with the ng generate component command, Angular creates a .css file for the component. We want to tell Angular to create a .scss file instead. We can do this in the schematics section of the angular.json file.

Open the angular.json file in the root of the FredsCars project and modify the schematics section with the following code.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "FredsCars": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },

Global Stylesheet

Since we are switching to scss files from css, we need to change the global stylesheet extension and update the references in the angular.json file.

In the FredsCars/src folder rename the styles.css file to styles.scss. Then in the angular.json file update both styles sections to include a reference to the global styles.scss file along with our Angular Material indigo-pink css theme.

The following is the complete angular.json file after the above modifications.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "FredsCars": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/freds-cars",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": [
              "zone.js"
            ],
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "FredsCars:build:production"
            },
            "development": {
              "browserTarget": "FredsCars:build:development"
            }
          },
          "defaultConfiguration": "development",
          "options": {
            "proxyConfig": "src/proxy.conf.js"
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "FredsCars:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "tsConfig": "tsconfig.spec.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": [],
            "karmaConfig": "karma.conf.js"
          }
        }
      }
    }
  }
}

Update existing components

The last thing we need to do is change the .css extensions to .scss for each existing component and update the references in each component’s styleUrls property of the Component decorator.

Make the following modifications to the code files shown below.

Update filename extensions

  • In the FredsCars/src/app folder change the filename of app.component.css to app.component.scss
  • In the FredsCars/src/app/nav-menu folder change the filename of nav-menu.component.css to nav-menu.component.scss
  • In the FredsCars/src/app/vehicles folder change the filename of vehicles.component.css to vehicles.component.scss
  • In the FredsCars/src/app/welcome folder change the filename of welcome.component.css to welcome.component.scss.

The image below shows the folder structure with the new filename extensions.

Update component style references

Lastly we just need to update the references to the stylesheets with the new scss extensions for each component as shown below. Make the following code modifications in bold blue in the specified files.

FredsCars/src/app/app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
}

FredsCars/src/app/nav-menu/nav-menu.component.scss

import { Component } from '@angular/core';

@Component({
  selector: 'app-nav-menu',
  templateUrl: './nav-menu.component.html',
  styleUrls: ['./nav-menu.component.scss']
})
export class NavMenuComponent {
}

FredsCars/src/app/vehicles/vehicles.component.ts

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Vehicle } from './vehicle';
import { environment } from '../../environments/environment';

@Component({
  selector: 'app-vehicles',
  templateUrl: './vehicles.component.html',
  styleUrls: ['./vehicles.component.scss']
})
export class VehiclesComponent implements OnInit {
  public vehicles?: Vehicle[];
  
// rest of code

FredsCars/src/app/welcome/welcome.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-welcome',
  templateUrl: './welcome.component.html',
  styleUrls: ['./welcome.component.scss']
})
export class WelcomeComponent {
}

Test Saas

Let’s test that our Sass configuration is working by improving the look of the results table in the Vehicles component.

Open the vehicles.component.scss file in the FredsCars/src/app/vehicles folder and fill it with the contents below.

$lightBlue: #add8e6;

table {
  border-spacing: 0px;

  tr {
    &:nth-child(even) {
      background-color: $lightBlue;
    }
  }

  td, th {
    padding: 5px;
  }

  thead {
    tr {
      background-color: black;

      th {
        color: $lightBlue;
      }
    }
  }
}

Restart the application in debug mode and the results should look similar to the following.

In the above screenshot we improved the look of the Vehicles results table using some Saas features. Let’s talk a little about what we did here.

First, we defined a variable called lightBlue since we use this color more than once in our custom styling of the table.

$lightBlue: #add8e6;

Next we open a nesting structure for the table element and set the border spacing between table cells to 0 pixels.

table {
  border-spacing: 0px;

Next for all tr elements within the table element we set the background color to the color of our lightBlue variable if the tr element is an even numbered row.

$lightBlue: #add8e6;

table {
  border-spacing: 0px;

  tr {
    &:nth-child(even) {
      background-color: $lightBlue;
    }
  }

Then for all td and th elements we set the padding to five pixels.

td, th {
    padding: 5px;
}

Finally, we target all child tr elements of the thead element setting the background of the header row to black and the contents of each header cell to the color of our lightBlue variable.

thead {
    tr {
        background-color: black;

        th {
          color: $lightBlue;
        }
    }
}

What’s Next

In this module we configured our application to use Sass and tested it out by improving the look of our Vehicle results table. In the next module we will add a header and footer to the application and again use Saas to customize the appearance.

< Prev
Next >

Leave a ReplyCancel reply

Chapter 1: Static HTML – Designing the landing page.

  • Static HTML – Designing the landing page.
  • Let’s get started!
  • Mock your site with HTML
  • Make CSS easy with Bootstrap
  • Mock your content
  • Introducing JavaScript
  • JavaScript Code Improvements
  • Results Data
  • Images and the HTML Image Element.
  • Revisiting Reusability for CSS and JavaScript
  • Reuse for HTML: PART 1
  • Reuse for HTML: PART 2
  • Details Page – Using a Bootstrap Component
  • Creating Links
  • Chapter One Conclusion

Chapter 2: ASP.Net Core – Let’s talk Dynamic

  • Introduction to ASP.Net Core
  • What is .Net?
  • What is ASP.Net
  • Introduction to Entity Framework Core

Chapter 3: ASP.Net MVC Core – Models, Views, and Controllers [ASP.Net Core v9]

  • Introduction to ASP.Net Core MVC
  • Create the project: ASP.Net Core MVC
  • Explore the ASP.Net Core Empty Web Project Template
  • Configure the Application for MVC
  • Create a Controller: Home Controller
  • Create a View: Index View for the Home Controller
  • Install Bootstrap using Libman
  • Create the Layout template
  • Create the Model
  • Install EF Core & Create the Database
  • Seed the Database: Loading test data
  • DI (Dependency Injection): Display a List of Vehicles
  • Repository Pattern: The Vehicles Repo
  • Unit Test 1: Home Controller Can Use Vehicle Repository
  • Unit Test 2: Vehicle Repository Can Return List
  • Add the ImagePath Migration and Thumbnail images to results
  • Pagination: Create a Custom Tag Helper
  • Sorting
  • Category Filter
  • Partial View: Break out the vehicle results
  • View Component: Create dynamic category buttons
  • Create the Details page
  • Create the Create Page

Chapter 7: Using Server Side & Client Side technologies together. [ASP.Net Core v7 & Angular v15]

  • Intro to Full Stack Development
  • Fred’s Cars – Full Stack Development
  • Prepare the environment
  • Create the Visual Studio Solution
  • Add the ASP.Net Core Web API project
  • Add the Angular Project
  • Wire it up!
  • WeatherForecast: Understanding the basics
  • Vehicles API Controller: Mock Data
  • Vehicles Angular Component: Consuming Data
  • Routing and Navigation
  • Using a Component Library: Angular Material
  • Our first Angular Material Component: MatToolbar
  • Configuring for Saas: CSS with superpowers
  • Create the Header & Footer components
  • Displaying Results with MatTable
  • Loading: Using a Progress Spinner
  • MatTable: Client-Side Paging and Sorting
  • MatSidenav: Create a Search Sidebar
  • MatCheckbox: Category Search UI
  • Adding an image to the welcome page
  • Create the database with Entity Framework Core migrations
  • MatPaginator & PageEvent: Custom Server-Side Paging
  • Unit Testing: Custom Server-Side Paging
  • Repository Pattern: VehicleRepository
  • Unit Test: Paging in the Vehicles controller
  • Server-Side Sorting
  • Unit Tests: Sorting
  • Filter (Quick Search)
  • Unit Tests: Filter feature
  • Advanced Search: Categories
  • Unit Tests: Search by category
  • Progress Spinner: Final Fix

TOC

  • What were WebForms?
  • Enter MVC
    • Understanding MVC
    • Advantages of MVC
  • ASP.Net Core MVC – A total rewrite
  • ASP.Net Core 2 MVC – Here come Razor Pages
    • Understanding Razor Pages
  • ASP.Net Core 3 – Dropping the MVC reference
    • Understanding Blazor
  • Dropping the MVC reference
  • Hello .Net 5!
  • What’s Next? – Here comes .Net 6.

Recent Posts

  • Angular Commands Cheat Sheet
  • Installing Git for Windows
  • Installing Postman
  • Installing SQL Server 2022 Express
  • Installing Visual Studio 2022

Recent Comments

No comments to show.

Archives

  • November 2023
  • October 2023
  • June 2023
  • October 2021

Categories

  • Angular
  • ASP.Net
  • Environment Setup
  • See All
  • SQL Server
  • Visual Studio
  • Web API & Rest Services

WordPress Theme Editor

Copyright © 2025 Web Development School.

Powered by PressBook Blog WordPress theme