html - 内部运行时 css 干扰页面默认 CSS

标签 html css angularjs

我需要在我的 angularjs 代码中绑定(bind) html。

<div class="preview-container" slimscroll="{height: '', color: '#00AAFF', alwaysVisible: 'true'}">
    <div ng-bind-html='previewHtml' class="preview-container"></div>
</div>

previewHtml 的值是从服务器检索的,由它自己的 css 样式组成。 previewHtml 的内部 css 对主机页面的默认 css 造成干扰。

从服务器检索到的 previewHtml 内容将如下所示。

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->
    <style type="text/css">
       ...some value 
    </style>
    <table > 
        ...some value  
    </table>
    </div>

有什么办法可以避免内部/运行时css引起的这种干扰

最佳答案

确保这一点的最好方法是使用内联样式,它比 <style> 中的样式更具体。标签。

 <div style="your_preview_style: here;" slimscroll="{height: '', color: '#00AAFF', alwaysVisible: 'true'}">
    <div ng-bind-html='previewHtml' class="preview-container"></div>
 </div>

还建议在您的 css 类名称中使用前缀,例如:

appInitial-preview-container

这可能会在不使用内联样式的情况下解决您的问题。

关于html - 内部运行时 css 干扰页面默认 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53514940/

相关文章:

html - 定位待办事项列表元素的问题

python - 为什么我的链接提取不起作用?

javascript - 如何为div内的每个元素设置边框颜色?

css - 如何在 Rails 元素中使用没有类且没有 Bootstrap 的 FontAwesome?

angularjs - 单击时 div 中的 Angular 动画

javascript - Angular 工厂只返回部分资源响应

javascript - 从被点击的元素image src中放入image src并更新数据

javascript - 将表 HTML 转换为 JSON

javascript - 显示表格单元格内容 onClick 如果相应的 Checkbox 被选中

javascript - AngularJS:templateUrl 推迟 Controller 的构建,相关代码中断