覆盖我无法访问的样式

时间:2019-01-17 13:21:35

标签: jquery html css class iframe

我正在尝试覆盖我无法访问的样式表中声明的样式。我正在尝试在iframe上删除height:auto,因为它已损坏,无法在android和移动设备上正常工作。

iframe运行一个预订系统,并且整个阶段都有可变高度的阶段,因此设置高度值将不起作用,我只需要覆盖自动高度部分即可。

.main iframe{width: 100%; height: auto !important;}

如果我能以某种方式删除高度自动程序,它将解决我的问题,我只是不知道如何实现此目的,我尝试在下面使用一排jquery,但这也不起作用。

$( "iframe" ).removeClass( "main iframe" );

任何帮助和建议将不胜感激

谢谢

2 个答案:

答案 0 :(得分:0)

尝试使用下面的代码,希望它能起作用...

$( "iframe" ).prop('style','width: 100%;');

答案 1 :(得分:0)

您不需要使用 JavaScript / jQuery 来取消设置height属性。

您只需要在CSS中添加另一种样式,以更高的特异性定位iframe,如下所示:

// original style property
.main iframe{width: 100%; height: auto !important;}

// replace "body" with any parent element wrapping your ".main" element
// Change 20% to whatever new value you want to set for the element's height
body .main iframe{height: 20% !important;}

检查并运行下面的代码段,以获取上述方法的实际示例:

/* CSS */
button {
   background-color: green !important; // old color
}
div button {
   background-color: red !important; // new color
}
<!-- HTML -->
<div>
  <button>
    ABCD
  </button>
</div>