How to resolve Bootstrap clash with Salesforce
Is it possible to use Bootstrap in a Visualforce page without having to use standardStylesheets="false"
and showHeader="false"
?
Answer is YES.
Here is the actual problem being faced while using bootstrap with salesforce.
Is it possible to use Bootstrap in a VFP without having to use standardStylesheets="false" and showHeader="false"? When I solely add in the stylesheets tag, my whole page is altered a little bit. The font is much larger but that is the only change. Even if I put in a styleClass="btn btn-primary on a button, I get no response from Bootstrap. That is until I add in the two tags, standardStylesheet=false and showHeader=false. I also am unable to override the standard style with inline style editing or style tags in the header. So is it possible to use Bootstrap in conjunction with the standard Salesforce styles? Without having to overwrite the page with an iFrame? |
The reason the CSS goes all over the place is that Salesforce uses the same class names and properties as Bootstrap. If there's a conflict, Salesforce wins. There's two reasons I can think of that this would happen, either Salesforce is using
!important
after each property, or Salesforce renders their stylesheets after everything else and because CSS literally cascades, the last properties rendered are used, any before it are ignored. The latter is most likely.
One way to do this would be to use namespacing within the CSS itself. This means you wouldn't be able to call Bootstrap from a CDN, rather you'd need to reference it as a static resource.
So here are the steps to make it work.
1. Download the bootstrap files.
2. open bootstrap.css file.
3. Navigate to http://winless.org/online-less-compiler
4. copy paste bootstrap.css code like below in there.
.BS {
//paste bootstrap.css code here
}
5. now take the generated code and save back in the bootstrap.css file.
Now you are good to use bootstrap inside salesforce.
Only thing is that you need to have a wrapping div with class 'BS' applied.
Comments
Post a Comment