apply external CSS to specific area

前端 未结 3 416
挽巷
挽巷 2021-01-18 05:17

I\'d like to import an external CSS (eg. Bootstrap) into my site-- the problem is I\'d like to apply the Bootstrap styles only to a specific region of the page. When I inclu

相关标签:
3条回答
  • 2021-01-18 05:46

    I've only tried this locally and not given it any thorough testing but it seems to work fine. I created a div around the content and assigned it an id. Then prefixed all of the bootstrap selectors with the id I assigned the surrounding div. The prefixing was done with a couple of search and replace operations. Perhaps it can be done easier with less

    Forgot to mention that the body selector of the bootstrap.css has to be replaced with the id and not prefixed like the other selectors.

    0 讨论(0)
  • 2021-01-18 05:56

    The only way to do this is to have a separate iframe for the content you want to style with Bootstrap (unless you want to edit the Bootstrap CSS, and add your outer div's selector to the beginning of EVERY rule).

    HTML5 introduced the new scoped attribute, which is made specifically for your use case, but has not yet been implemented by any one of the major browsers.

    If you are using jQuery (which you probably are, since all of Bootstrap's Javascript functionality is dependent upon jQuery), you might wanna try Simon Madine's jQuery Scoped CSS plugin.

    0 讨论(0)
  • 2021-01-18 05:57

    Import Bootstrap before your own styles. That way your own styles will overwrite the changes made by Bootstrap where applicable.

    0 讨论(0)
提交回复
热议问题