Best practices

There are a lot of best practices when it comes to customizing Bootstrap themes. In order to avoid the most common mistakes that developers make, the following is a list of the most important things to be kept in mind:

  • Use similar selectors when overriding styles: You should always use the exact same selector when you are overriding a style to make sure that the selector is efficient enough. You can use tools (for example, Chrome development tools) to find the correct selectors.
  • Make sure that the files are included in the correct order: Remember that you always need to include your overrides after the original styles, otherwise they will not work.
  • Do not modify the source files: It is considered bad practice to modify the source files directly because it makes both maintaining your customizations and upgrading the source files difficult, sometimes even impossible. There are no exceptions in this case.
  • Do not use !important unless absolutely necessary: You should avoid using !important in your styles because it usually means that your selector is either wrong or not efficient enough. However, there are some rare cases where you need to use !important in order to override a style. If you do, try to learn why you have to use it before doing so. A good article on this topic can be found at http://coding.smashingmagazine.com/2010/11/02/the-important-css-declaration-how-and-when-to-use-it/.
  • Use classes to style elements and IDs for binding JavaScript functionalities: This way, you can distinguish between the attributes used to define styles for an element and the attributes that are used to identify it through JavaScript.
  • Learn how Cascade works: You can improve your styles quite a bit if you understand how CSS Cascade works, that is, how browsers parse your styles and determine which styles are more significant than others. A good article on this topic can be found at http://coding.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.35.122