Override Bootstrap variables in a Theme

Overview

The storefront theme is implemented as a skin on top of Boostrap:
Bootstrap
getbootstrap
Sometimes it is necessary to adjust SCSS variables if you want to change the look of the Storefront for example default variables like $border-radius which is defined by Boostrap. This guide will show how you can override those SCSS variables.

Prerequisites

All you need for this guide is a running Shopware 6 instance and full access to both the files, as well as the command line. You also need to have an installed and activated theme which is assigned to a sales channel. Checkout the Create a first theme guide if you have not yet a working theme setup.

Override default SCSS variables

Bootstrap 4 is using the !default flag for it's own default variables. Variable overrides have to be declared beforehand.
More information can be found here.
To be able to override Bootstrap variables there is an additional SCSS entry point defined in your theme.json which is declared before @Storefront.
This entry point is called overrides.scss:
<plugin root>/src/Resources/theme.json
1
{
2
"name": "SwagBasicExampleTheme",
3
"author": "Shopware AG",
4
"views": [
5
"@Storefront",
6
"@Plugins"
7
],
8
"style": [
9
"app/storefront/src/scss/overrides.scss", <-- Variable overrides
10
"@Storefront",
11
"app/storefront/src/scss/base.scss"
12
],
13
"script": [
14
"@Storefront",
15
"app/storefront/dist/storefront/js/just-another-theme.js"
16
],
17
"asset": [
18
"@Storefront",
19
"app/storefront/src/assets"
20
]
21
}
Copied!
In the <plugin root>/src/Resources/app/storefront/src/scss/overrides.scss you can now override default variables like $border-radius globally and set its value to 0 to reset it in this case:
<plugin root>/src/Resources/app/storefront/src/scss/overrides.scss
1
/*
2
Override variable defaults
3
==================================================
4
This file is used to override default SCSS variables from the Shopware Storefront or Bootstrap.
5
​
6
Because of the !default flags, theme variable overrides have to be declared beforehand.
7
https://getbootstrap.com/docs/4.0/getting-started/theming/#variable-defaults
8
*/
9
​
10
$border-radius: 0;
11
​
12
// some other override examples
13
$icon-base-color: #f00;
14
$modal-backdrop-bg: rgba(255, 0, 0, 0.5);
15
$disabled-btn-bg: #f00;
16
$disabled-btn-border-color: #fc8;
17
$font-weight-semibold: 300;
Copied!
After saving the overrides.scss file and running bin/console theme:compile go and check out the Storefront in the browser. The border-radius should be removed for every element.
Please only add variable overrides in this file. You should not write CSS code like .container { background: #f00 } in this file.
When running ./psh.phar storefront:hot-proxy in the development template or ./bin/watch-storefront.sh in the production template, SCSS variables will be injected dynamically by webpack. When writing selectors and properties in the overrides.scss the code can appear multiple times in your built CSS.

Next steps

Now that you know how to override Boostrap variables, here is a list of related topics which might be interesting for you.
Last modified 5mo ago