html - CSS:分别删除和忽略所有以前的属性?

标签 html css

我们的应用程序将集成在一个 I-Frame 上,现有的样式文件会覆盖一些规则。我知道,我可以说对于某个属性它很重要并且不会在我自己的 css 文件中覆盖,比如

pre {
    width: 200px !important;
}

问题是,我不知道哪些属性会被覆盖,有时是颜色,有时是媒体查询中的大小或行为。这是一家非常大的公司,没有机会修改他们的 from-different-sources-on-the-fly-patched-up-css-file,这是一个糟糕的情况。

因此我希望有这样的功能:

pre {
   forget_all_your_previous_settings: yes;
   convert_all_properties_to_w3c_standard: yes; 
}

有没有可能做到这一点?我们目前的解决方法是将所有内容都定义为新的,这是一个非常耗时且成本高的问题。

最佳答案

您可以使用all: revert !important;

The all property in CSS resets all of the selected element's properties, except the direction and unicode-bidi properties that control text direction.

了解更多 here

.element {
  width: 300px !important;
  background: black !important;
  color: red !important;
  font-size: 3em !important;
}

.element {
  all: revert !important;
}
<div class="element">
  element
</div>

Working Fiddle

编辑: 并非所有浏览器都支持,要获得全面支持,您可以做 this :

.element {
    animation : none;
    animation-delay : 0;
    animation-direction : normal;
    animation-duration : 0;
    animation-fill-mode : none;
    animation-iteration-count : 1;
    animation-name : none;
    animation-play-state : running;
    animation-timing-function : ease;
    backface-visibility : visible;
    background : 0;
    background-attachment : scroll;
    background-clip : border-box;
    background-color : transparent;
    background-image : none;
    background-origin : padding-box;
    background-position : 0 0;
    background-position-x : 0;
    background-position-y : 0;
    background-repeat : repeat;
    background-size : auto auto;
    border : 0;
    border-style : none;
    border-width : medium;
    border-color : inherit;
    border-bottom : 0;
    border-bottom-color : inherit;
    border-bottom-left-radius : 0;
    border-bottom-right-radius : 0;
    border-bottom-style : none;
    border-bottom-width : medium;
    border-collapse : separate;
    border-image : none;
    border-left : 0;
    border-left-color : inherit;
    border-left-style : none;
    border-left-width : medium;
    border-radius : 0;
    border-right : 0;
    border-right-color : inherit;
    border-right-style : none;
    border-right-width : medium;
    border-spacing : 0;
    border-top : 0;
    border-top-color : inherit;
    border-top-left-radius : 0;
    border-top-right-radius : 0;
    border-top-style : none;
    border-top-width : medium;
    bottom : auto;
    box-shadow : none;
    box-sizing : content-box;
    caption-side : top;
    clear : none;
    clip : auto;
    color : inherit;
    columns : auto;
    column-count : auto;
    column-fill : balance;
    column-gap : normal;
    column-rule : medium none currentColor;
    column-rule-color : currentColor;
    column-rule-style : none;
    column-rule-width : none;
    column-span : 1;
    column-width : auto;
    content : normal;
    counter-increment : none;
    counter-reset : none;
    cursor : auto;
    direction : ltr;
    display : inline;
    empty-cells : show;
    float : none;
    font : normal;
    font-family : inherit;
    font-size : medium;
    font-style : normal;
    font-variant : normal;
    font-weight : normal;
    height : auto;
    hyphens : none;
    left : auto;
    letter-spacing : normal;
    line-height : normal;
    list-style : none;
    list-style-image : none;
    list-style-position : outside;
    list-style-type : disc;
    margin : 0;
    margin-bottom : 0;
    margin-left : 0;
    margin-right : 0;
    margin-top : 0;
    max-height : none;
    max-width : none;
    min-height : 0;
    min-width : 0;
    opacity : 1;
    orphans : 0;
    outline : 0;
    outline-color : invert;
    outline-style : none;
    outline-width : medium;
    overflow : visible;
    overflow-x : visible;
    overflow-y : visible;
    padding : 0;
    padding-bottom : 0;
    padding-left : 0;
    padding-right : 0;
    padding-top : 0;
    page-break-after : auto;
    page-break-before : auto;
    page-break-inside : auto;
    perspective : none;
    perspective-origin : 50% 50%;
    position : static;
    /* May need to alter quotes for different locales (e.g fr) */
    quotes : '\201C' '\201D' '\2018' '\2019';
    right : auto;
    tab-size : 8;
    table-layout : auto;
    text-align : inherit;
    text-align-last : auto;
    text-decoration : none;
    text-decoration-color : inherit;
    text-decoration-line : none;
    text-decoration-style : solid;
    text-indent : 0;
    text-shadow : none;
    text-transform : none;
    top : auto;
    transform : none;
    transform-style : flat;
    transition : none;
    transition-delay : 0s;
    transition-duration : 0s;
    transition-property : none;
    transition-timing-function : ease;
    unicode-bidi : normal;
    vertical-align : baseline;
    visibility : visible;
    white-space : normal;
    widows : 0;
    width : auto;
    word-spacing : normal;
    z-index : auto;
}

关于html - CSS:分别删除和忽略所有以前的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40215855/

相关文章:

javascript - 使用 jQuery 将 Class 添加到 div 中的前 5 个元素

html - 如何使所有响应图像的高度相同

html - 具有 z-index 子对象的对象

javascript - Canvas 宽度和高度计算已关闭

html - 使用 Twitter Bootstrap 显示按钮

html - 使用 CSS 填充表格在 IE 上不起作用

javascript - 在 html Canvas 中从线 Angular 和 x 正轴创建基于圆

javascript - 如何在iframe内制作固定div

图片库的 CSS 无法在图片周围获得统一的填充宽度

css - SVG 动画不适用于 Google Chrome 或 IE