【问题标题】:Disable (exclude) bootstrap for one div on a page禁用(排除)页面上一个 div 的引导程序
【发布时间】:2018-02-07 04:11:31
【问题描述】:

我有一个应用程序可以提取自定义旧电子邮件并将它们显示在 DOM 的页面上。我想从引导 css 中排除包含此 HTML 电子邮件的 div。像这样的:

<div class="email_container">
<!-- bootstrap CSS shouldn't apply here-->
<div class="email">
<!-- neither here-->
</div>
</div>

有没有办法做到这一点?我做了一些研究,看到人们谈论 LESS 和 SASS 来解决这个问题,但是有没有办法在没有他们的情况下做到这一点,因为我不想仅仅为此目的在我的项目中包含 LESS 或 SASS。

【问题讨论】:

  • 可能听起来很脏,但您可以将 HTML 电子邮件内容放入 iframe,这样您的样式就不会级联。
  • 关于排除看here
  • !important 覆盖规则。
  • @Stuart 我确实想到了,但我不能,因为我必须对该电子邮件 HTML 进行 DOM 操作
  • @DannyFardyJhonstonBermúdez 我无法覆盖,因为样式也来自远程源,我将不得不手动覆盖它们中的每一个,这不是最佳的

标签: javascript html css twitter-bootstrap


【解决方案1】:

我认为你应该使用这个类来重置email_container 下的所有 CSS。在 CSS 中它写着.reset-this *,所以.reset_this 下的元素将被重置,然后你可以添加你想要的。

这不是我创建的,取自链接resetting CSS

JSFiddle Demo

HTML

<div class="email_container reset-this">
<!-- bootstrap CSS shouldn't apply here
<div class="email">
<!-- neither here-->
</div>
</div>

CSS:

.reset-this * {
    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;
    /* basic modern patch */
    all: initial;
    all: unset;
}

/* basic modern patch */

#reset-this-root {
    all: initial;
    * {
        all: unset;
    }
}

【讨论】:

    【解决方案2】:

    如果引导程序影响所有div进入站点,您不能不排除某些css样式,例如:

    div {
      color: #000;
      font-size: 10px;
      /* some other styles */
    }
    

    如果 bootstrap 或只是另一个 css 框架有,所以你不能省略上面写的样式,所以你必须的替代方法是在你的“排除 div”中添加一个自定义类,试试这个

    <div class="myCustomClassToExclude">
    </div>
    

    你的css风格

    .myCustomClassToExclude {
      color: #FFF; /*override color*/
      font-size: 20px; /*override font-size*/
      /* here you need to override all the style already set by bootstrap */
    }
    

    【讨论】:

      【解决方案3】:

      实现此目的的一种快速而肮脏的方法是在将整个引导样式表包装成一个 CSS 类之后,使用 CSS 预处理器重新编译它:

      .bootstap-include{  
         /* Content of bootstap.css .. */
      }
      

      要使其正常工作,该文件需要进行一些调整:

      • 将文件顶部的:root 选择器替换为&amp;
      • 将文件顶部的body 选择器替换为&amp;
      • 删除字符集声明@charset "UTF-8";

      在这里查看一支工作笔:https://codepen.io/kisaure/pen/WNXOBdz

      我没有测试它,但我认为 bootsrap.js 功能和其他一些东西可能会被破坏。

      【讨论】:

        猜你喜欢
        • 2014-09-26
        • 2021-10-01
        • 1970-01-01
        • 2013-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-19
        • 1970-01-01
        相关资源
        最近更新 更多