Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Stylesheet to one tag and descendents

I want to use twitter bootstrap for some site I am working on. This site requires a pre-set template to be used for certain parts of the page.

If I include the twitter bootstrap stylesheet it messes up the original template.

I want to include the external bootstrap.cc stylesheet but make it work only on tags which are a descendent of class="mycontent"

<html>
<link href="original stylsheet.css">
<link href="bootstrap.css">
...
...
<div class="header">
original stlesheet to be used here
</div>
<div class="mycontent">
bootstrap css to work for all descendents of my content
</div>

I know one way is to edit the css and add .mycontent before each and every tag. But I was wondering if there was a smarter solution

like image 998
Roopak Venkatakrishnan Avatar asked Aug 24 '12 13:08

Roopak Venkatakrishnan


1 Answers

Scoped CSS

If scope attribute is present, then <style> applies only to its parent element.

<div>
  <style scoped>
  /* your css here */
  <style>
  <!-- content -->
</div>

It lacks of browser support, but there is a polyfill: jQuery Scoped CSS plugin.

Additional reading: Saving the Day with Scoped CSS.


Current browser support: http://caniuse.com/#feat=style-scoped

like image 53
Pavlo Avatar answered Sep 29 '22 21:09

Pavlo