Replies: 9 comments
-
The way I work with Bootstrap 4 is using its SCSS files. And all I'll do is work with the SCSS variables found in Bootstrap like $font-size rather than me doing the font size. So that way I can tinker with bootstrap rather than say downloading a custom Bootstrap file. Of course, don't edit the main files of bootstrap (just in case it updates). Just work with the variables. I use BEM to add my own components. There is no interference with BEM and a framework. I guess you mean the specificity of Bootstrap 4 vs BEM? I do get a couple issues... But as I said you don't have to follow 1 CSS methodology religiously. You can use different ones and it's okay to use 2 classes e.g. Maybe this article will help for you? Kind regards, Mic Sumner |
Beta Was this translation helpful? Give feedback.
-
Keeping perfect bem might be tricky with bootstrap, because of css selectors specificity.
This way your component has specific style that overrides the global component style, and because the selector is not nested, but "combined" this keep all the benefits of bem. The other approach would be to recreate all the basic boostrap styles for bem flat selectors approach, I wonder if someone did this already? |
Beta Was this translation helpful? Give feedback.
-
A good approach is to just create a BEM structure for your markup, and extend the relevant bootstrap classes into your SCSS. You can then have a set of variables that are for your BEM structure, and override the bootstrap variables at your choice. I have a blog post/tutorial in progress atm that does exactly this - It should be landing within the next 2 weeks if i get the time to finish it. I will post the link on here once up. Using this approach will keep your html semantic, and your automation tests less fragile as you do not have the VERY verbose bootstrap html in your components. |
Beta Was this translation helpful? Give feedback.
-
@martinfletcher I assume this uses Sass |
Beta Was this translation helpful? Give feedback.
-
Yes. Looks like someone had already written a tutorial back in 2014: BEM, SASS and Bootstrap. |
Beta Was this translation helpful? Give feedback.
-
In this 2014 tutorial, Anderson Orui explains a good practice for writing css in the BEM methodology, using scss and bootstrap, I recently read his tutorial, but I have a question that I didn't find the solution, the problem when I write my own classes extending the bootstrap classes, "bootstrap java script functions don't work anymore". I really appreciate anyone who can help me! Sorry for my English because I'm not very fluent "google translate kkk". |
Beta Was this translation helpful? Give feedback.
-
When using this approach, you need to initialise the bootstrap js components yourself, as by convention, the bootstrap javascript looks for the bootstrap classes. |
Beta Was this translation helpful? Give feedback.
-
Got it, so I have to initialize the js bootstrap components. Would it be correct to change the bootstrap js modules? because in scss it's not I believe that the use of webpack would also be recommended, I believe that with it the modules will be compiled into a single .js file, but I don't know how to do this. I would like guidance on the correct path I should follow. Thank you for your help |
Beta Was this translation helpful? Give feedback.
-
@GabrielSantosLemos - Are you using bootstrap via jQuery or the ESM modules? Take a look at the docs for info: https://getbootstrap.com/docs/5.0/getting-started/javascript/ |
Beta Was this translation helpful? Give feedback.
-
Recently I came across BEM methodology. And I really like it. However I haven's studied it in depth.
Before I take a plunge into BEM (put my time and attention into really learning it to effectively apply it into my projects) ; I would appreciate if somebody who is more experienced with BEM could clear nagging doubt that I am having right now.
Is it practicable to use BEM if I have to use Bootstrap for my projects? Do BEM and Bootstrap 'mix' well? Are there any pitfalls in using BEM with Bootstrap?
Beta Was this translation helpful? Give feedback.
All reactions