内联CSS没有被外部CSS中的!important重写

时间:2015-07-16 13:35:29

标签: css

我正在尝试让this site做出回应。

我已将以下CSS添加到Wordpress主题的custom.css

li#vfb-3 {
    color: #808080;
}

p#form_success, .vfb-form-success {
    color: #CCFFCC;
}

#menu {
    background-image: none;
    background: #ffffff;
/* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlNmU2ZTYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
    background: -moz-linear-gradient(top,#ffffff 0%,#e6e6e6 100%);
/* FF3.6+ */
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#ffffff),color-stop(100%,#e6e6e6));
/* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,#ffffff 0%,#e6e6e6 100%);
/* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,#ffffff 0%,#e6e6e6 100%);
/* Opera 11.10+ */
    background: -ms-linear-gradient(top,#ffffff 0%,#e6e6e6 100%);
/* IE10+ */
    background: linear-gradient(to bottom,#ffffff 0%,#e6e6e6 100%);
/* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',endColorstr='#e6e6e6',GradientType=0);
/* IE6-8 */
}

@media (max-width:959px) {
    .container, #menu, #featured, #slides, .slide .overlay, .slide .overlay2 {
        width: 100% !important;
    }

    #featured {
        height: auto !important;
    }

    #header {
        height: 168px;
    }

    img {
        max-width: 100% !important;
        height: auto;
    }

    #menu {
        height: auto;
    }
}

@media (max-width:461px) {
    .container, #menu, #featured, #slides, .slide .overlay, .slide .overlay2 {
        width: 100%;
    }

    #featured {
        height: auto !important;
    }

    #header {
        height: 202px;
    }

    img {
        max-width: 100% !important;
        height: auto;
    }

    #menu {
        height: auto;
    }
}

@media (max-width:337px) {
    .container, #menu, #featured, #slides, .slide .overlay, .slide .overlay2 {
        width: 100%;
    }

    #featured {
        height: auto !important;
    }

    #header {
        height: 236px;
    }

    img {
        max-width: 100% !important;
        height: auto;
    }

    #menu {
        height: auto;
    }
}

图像滑块包含#slides元素,该元素由以下产生:

<div id="slides" style="background-image: none; width: 960px; height: 447px;">

但是,当我将浏览器宽度减少到960像素以下时,我的#slides {width: 100% !important;} CSS未应用。

为什么会这样?感谢。

2 个答案:

答案 0 :(得分:0)

您的结构有点像下面的代码 -

<div id="slides"></div>
  <div class="slide" style="width:960px;...*other styles*">
    *tags within*
  </div>
  <div class="slide" style="width:960px;...*other styles*">
    *tags within*
  </div>
  <div class="slide" style="width:960px;...*other styles*">
    *tags within*
  </div>
  <div class="slide" style="width:960px;...*other styles*">
    *tags within*
  </div>
</div>

现在即使 #slides 在屏幕尺寸小于960px时将宽度设为100%,其子项 .slide 也会占用960px,图像标记也是如此在.slides内。 您必须覆盖 .slides img 以及宽度:100%as -

@media (max-width:959px) {
  #slides > .slide, #slides img {
    width: 100% !important;
  }
}

答案 1 :(得分:0)

此图像滑块由Wordpress主题生成。

我用专用的滑块插件取而代之,问题就消失了,因为专用的插件内置了响应能力。