ScandiPWA
Create Magento AppCreate ScandiPWA AppUser ManualGitHub
  • Why Scandi
  • πŸš€Quick-start Guide
  • πŸ—ΊοΈRoadmap
  • Introduction to the Stack
    • CMA, CSA, and ScandiPWA
    • Challenges
  • Setting up Scandi
    • Storefront Mode Setup
      • Proxying requests to server
    • Magento Mode Setup
    • Existing Magento 2 setup
    • Magento Commerce Cloud setup
    • Updating to new releases
      • Storefront mode upgrade
      • Magento mode upgrade
      • CMA upgrade
      • CSA upgrade
      • Custom ScandiPWA composer dependency update
      • Local ScandiPWA Composer Package Setup
    • Docker Setup [deprecated]
      • Legacy Docker setup
      • Migrating to CMA & CSA
  • Developing with Scandi
    • Override Mechanism
      • Overriding JavaScript
        • Overriding classes
        • Overriding non-classes
      • Overriding Styles
      • Overriding the HTML / PHP
      • Parent Themes
    • Extensions
      • Creating an extension
      • Installing an extension
      • Migrating from 3.x to 4.x
      • Publishing an extension
      • Extension Terminology
    • Working With Magento
      • Magento troubleshooting
      • Working with Magento modules
      • Working with GraphQL
      • GraphQL Security
      • Working with "granular cache"
    • Developer Tools
      • Debugging in VSCode
      • ScandiPWA CLI
      • Configuring ESLint
      • CSA Commands
    • Deploying Your App
      • Build & Deploy Android app
      • Build & Deploy iOS app
  • Structure
    • Directory Structure
    • Building Blocks
      • Components
        • Styling Components
      • Routes
      • Redux Stores
      • GraphQL Queries
      • Global Styles
      • The Util Directory
      • Type Checking
    • Application assets
    • Code Style
      • JavaScript Code Style
      • SCSS Code Style
  • Tutorials
    • Customizing Your Theme
      • Styling
        • Customizing the Global Styles
        • Adding a New Font
        • Overriding a Components Styles
        • Extending a Component's Styles
      • Customizing JavaScript
        • Customizing the Footer Copyright
        • Adding a New Page
        • Adding a Section in My Account
        • Adding a Tab on the Product Page
        • Creating a New Redux Store
    • Payment Method Integration
      • Setting Up for Development
      • Redirecting to the Payment Provider
      • Handling the Customer's Return
    • Creating a Custom Widget
      • Scandi CMS System Overview
      • Creating a Magento Widget
      • Implementing the Rendering
    • Video Tutorials
      • #1 Setting up and talking theory
      • #2 Templating in React
      • #3 Overriding a file
      • #4 Styling the application
      • #5 Patterns of ScandiPWA
    • Dark Mode Extension
    • Deploying Native Apps
    • Product 3D Model Extension
      • Part 1: Magento 3D Model Uploads
      • Part 2: GraphQL API
      • Part 3: Scandi Frontend
    • Social Share, Full Extension Development
      • STEP-1 and 2 Creating Magento 2 Module
      • STEP-3 Backend Configurations Settings
      • STEP-4 Simple GraphQl and Resolver
      • STEP-5 Creating Extension, Base Redux Store
      • STEP-6 Extension plugins
      • STEP-7 GraphQL types, Helpers
      • STEP-8 Query Field and FieldList
      • STEP-9 render Plugins and MSTP Plugin, Component creation
      • STEP-10 SocialShare Component Development
      • STEP-11 SocialShare for CategoryPage
      • TASK-1 Changing LinkedIn to Twitter
      • STEP-12 Comments for Admin Users
      • STEP-13 Final, bugfixes
    • Accessing Magento 2 Controllers
      • STEP-1 Creating Magento 2 Module
      • STEP-2 - Create Magento 2 Frontend Route and Basic Controller
      • STEP-3 Accessing Magento 2 Controller, Bypassing ScandiPWA frontend
      • STEP-4 Creating ScandiPWA Extension with additional dependencies
      • STEP-5 Creating Plugin and Axios request
  • About
    • Support
    • Release notes
    • Technical Information
    • Data Analytics
    • Contributing
      • Installation from Fork
      • Repository structure
      • Code contribution process
      • Submitting an Issue
      • Publishing ScandiPWA
Powered by GitBook
On this page
  • Overriding the Base Styles
  • Replacing a Component's Styles
  • Partially Overriding a Component's Styles

Was this helpful?

  1. Developing with Scandi
  2. Override Mechanism

Overriding Styles

PreviousOverriding non-classesNextOverriding the HTML / PHP

Last updated 4 years ago

Was this helpful?

You can adjust the styling of your theme in 3 different ways:

  • : The ScandiPWA theme includes a set of stylesheets in app/style that define the main look of the application. These define global settings, such as SCSS variables (style/abstract/_variables.scss), media query definitions (style/abstract/_media.scss), base styling for some HTML elements (style/base), CMS content styling (style/cms), and more. If you want to make global styling changes to these files, you can override them.

  • : Every component (and route) includes an associated stylesheet, named <component>.style.scss. If you wish to completely change the look of a component, you can replace these styles with your own.

  • : You can choose to keep the existing component's styles instead, and override some of them.

Overriding the Base Styles

The base styles are defined in the styles directory, and imported in styles/main.scss. In order to override a base style file, you need to copy over the chain of files that is used to import it.

For example, suppose we want to change the main theme color to an ocean blue. The primary color is defined in style/abstract/_variables.scss. Copy over this file to avoid missing any variables, and make the desired changes:

override: style/abstract/_variables.scss
$white: #fff;
$black: #0a0a0a;
$default-primary-base-color: #2387f2; // changed the color here
$default-primary-dark-color: #1259d4; // and here
$default-primary-light-color: #42bdf7; // and here!
$default-secondary-base-color: #eee;
$default-secondary-dark-color: #929292;
$default-secondary-light-color: #f8f8f8;
$font-muli: 'Muli', sans-serif;
$font-standard-size: 12px;
$font-mobile-size: 14px;

We also need to copy over the file that imports _variables.scss for the override to work. By inspecting the styling files, we can see that style/abstract/_variables.scss is imported in style/abstract/_abstract.scss, which is itself imported directly from style/main.scss. Hence, we need to copy over _abstract.scss and main.scss to their respective directories in our theme.

We can check that the theme's primary color has been successfully overridden:

Replacing a Component's Styles

Sometimes you may want to completely restyle a component, ignoring all original styles. For example, suppose we want to create an entirely new design for the CategoryPaginationLink component. All we need to do is create a stylesheet with the same path as the stylesheet from the parent theme we want to override. In this case, create a file in component/CategoryPaginationLink/CategoryPaginationLink.style.scss with the following contents:

override: component/CategoryPaginationLink/CategoryPaginationLink.style.scss
:root{
    --category-pagination-link-size: 50px;
    --category-pagination-link-text-size: 30px;
}

.CategoryPaginationLink {
    // configure layout and center text
    display: block;
    text-align: center;
    size: var(--category-pagination-link-text-size);
    line-height: var(--category-pagination-link-size);

    // set a circular shape with border-radius
    width: var(--category-pagination-link-size);
    height: var(--category-pagination-link-size);
    margin: 6px;
    border-radius: var(--category-pagination-link-size);

    // white text on a blue background
    background: var(--primary-base-color);
    color: #fff;

    // indicate hover/active state
    transition: opacity 100ms ease-out;
    opacity: 0.7;

    &:hover,
    &:focus,
    &_isCurrent {
        opacity: 1;
    }
}

With this override, any import of the CategoryPaginationLink stylesheet will resolve to our custom file. Hence, our stylesheet will be the one to be included in the final CSS file, resulting in this look:

Partially Overriding a Component's Styles

In some situations, you might want to keep the overall look of a component but change some minor aspect of it's styling. In such cases, it would be undesirable to copy the original stylesheet just to change a few lines of SCSS rules. ScandiPWA suggests a better approach: keeping the original stylesheet and creating an additional stylesheet that overrides some of the default styles.

Consider an example where we want to change the style of the heading of MyAccountOverlay - we want to make the text "Sign in to your account" italic.

First, we can define the styles we want to change. We can't keep the original name of the file, because then we will override it completely as shown in the previous section. The naming convention for partially overriding stylesheet files in ScandiPWA is to add .override to the file name:

override: component/MyAccountOverlay/MyAccountOverlay.override.style.scss
.MyAccountOverlay {
    &-Heading {
        font-style: italic;
    }
}

The styles we want to override are defined, but they will not be included in the CSS requested by the browser unless we import them somewhere. Styles in ScandiPWA are typically imported from the .component file, so override the .component file of MyAccountOverlay, by creating a file matching the original component file. We don't need to change any of the exported classes or components, so we can leave the existing exports unchanged, but we do need to add an additional import - our overridden styles:

override: component/MyAccountOverlay/MyAccountOverlay.component.js
// import the original component so that base styles are applied first
import 'SourceComponent/MyAccountOverlay/MyAccountOverlay.component';
// import our modified styles to override some of the default ones
import './MyAccountOverlay.override.style.scss';

// re-export all the original exports from the parent theme untouched
export * from 'SourceComponent/MyAccountOverlay/MyAccountOverlay.component';
export { default } from 'SourceComponent/MyAccountOverlay/MyAccountOverlay.component';

Now, we can verify that the new CSS rules have overridden some of the default ones, and the title is in italics:

Overriding the Base Styles
Replacing a Component's Styles
Partially Overriding a Component's Styles