我想为我正在处理的某些网站使用 Twitter Bootstrap 。此站点需要将预设模板用于页面的某些部分。
如果我包含 Twitter Bootstrap 样式表,它会弄乱原始模板。
我想包含外部 bootstrap.cc 样式表,但让它只适用于 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>
我知道一种方法是编辑 css 并在每个标签前添加 .mycontent。但我想知道是否有更聪明的解决方案
最佳答案
作用域 CSS
如果scope
属性存在,则 <style>
仅适用于其父元素。
<div>
<style scoped>
/* your css here */
<style>
<!-- content -->
</div>
它缺少浏览器支持,但有一个 polyfill:jQuery Scoped CSS plugin .
补充阅读:Saving the Day with Scoped CSS .
关于html - 将样式表限制为一个标签和后代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12110708/