1

I added bootstrap 4 to my site, but it overwrites many magento 2 core css.

So I added a new file THEME\web\css\bootstrap.less where I try to fix these problems, and added it to my THEME\Magento_Theme\layout\default_head_blocks.xml.

THEME\web\css\bootstrap.less:

body {
 font-family: 'Open Sans','Helvetica Neue',Helvetica,Arial,sans-serif !important;
 font-size: @font-size__base;
 line-height: 1.42857143;
}
.nav { display: block; }

But if I compile then I get NameError: variable @font-size__base is undefined in pub/static/frontend/company/fresh/de_DE/css/bootstrap.less on line 3, column 16:, because I am using the variable @font-size__base which is defined in lib\web\css\source\lib\variables\_typography.less

How can I use magento less core variables in my custom css file?

My theme inherits from magento luma.

asked Aug 27, 2020 at 11:50

1 Answer 1

0

Instead of creating new bootstrap.less file, please create _bootstrap.less file in <your_theme>/web/css/source/extends directory.

Then:

  1. Create the _extend.less file in <your_theme>/web/css/source/

  2. Import your _bootstrap.less in this file:

    @import 'extends/_bootstrap.less';

  3. Make sure that your theme inherits from Magento/luma or Magento/blank theme - this is necessary if you want to use Magento variables

  4. Recompile your styles

I hope this helps you. Thanks, Marcin

1
  • Thank you, but this will compile my bootstrap.less into the files styles-l.css and styles-m.css which both get loaded before the bootstrap 4 css file. This means that my overwrites will get overwritten again by bootstrap 4 ... So I need a separate css file which gets loaded after the bootstrap 4 css file. Commented Aug 27, 2020 at 14:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.