简体   繁体   English

网站的CSS取代了iframe样式

[英]Iframe style being overrridden by website's css

  1. I work for an adtech. 我为adtech工作。 We show ads using iframe but for one particular website where we are showing ads my iframe height is being overriden. 我们使用iframe展示广告,但是对于一个要展示广告的特定网站,我的iframe高度已被覆盖。

  2. The style that overrides my css style is as follows:- 覆盖我的CSS样式的样式如下:-

 #story-sec .led-content .cont-bot .right-side .news-detail-landing iframe:not(.instagram-media) { width: 100% !important; height: 200px!important; margin: 5px 0px; } 

  1. I create iframe dynamically using javascript. 我使用JavaScript动态创建iframe。 The site is overriding my css. 该网站覆盖了我的CSS。

var iframe = createHtmlElement("iframe");          
setAttributesForElement(iframe, { 'vspace':'0', 'hspace':'0', 'scrolling':'no', 'id':'myIframeId', 'frameborder':'0', 'marginwidth': '0', 'marginheight': '0', 'allowtransparency':'true', } );            
setStyle(iframe, {'margin':'0px', 'width':'100%', 'height':'100%', 'padding':'0px'} );

So in above code setAttributes and setStyle are function that I have which take input and set style adn attributes for html elements. 所以在上面的代码中,setAttributes和setStyle是我拥有的函数,它们接受输入并为html元素设置样式和属性。

  1. Is there a way to avoid my css being overridden ? 有没有办法避免我的CSS被覆盖? I tried searching for answers but got not much clarity. 我尝试寻找答案,但并不太清楚。

  2. I can set class named instagram-media for my iframe which solves the issue but the ads are placed on different sites so I might encounter same problem again. 我可以为iframe设置名为instagram-media的类,以解决此问题,但广告放置在不同的网站上,因此我可能会再次遇到相同的问题。 so looking for a permanent solution. 所以寻找一个永久的解决方案。

I had experience of work like that, so in those cases I would usually do this: - Target the iframe you created with > css pointer. 我曾经有过类似的工作经验,因此在这种情况下,我通常会这样做:-定位使用> css指针创建的iframe。 - Is there any possibility to set !important flags on your styles? -是否有可能在您的样式上设置!important标志? - Try to create a very long distinctive class name for your iframe. -尝试为iframe创建一个非常长的独特类名。

You mentioned adding a class resolves the issue but that you're worried about, another website using that same class and again over writing your css. 您提到添加一个类可以解决此问题,但您担心的是,另一个使用该类的网站又在编写CSS时过分。

Your best bet may be to simply use some really obscure class? 您最好的选择也许是简单地使用一些晦涩难懂的课程?

Like... 喜欢...

class="YourCompany_iframeCSS_InsertADateHere_AnAlphaNumericStringHere" 类= “YourCompany_iframeCSS_InsertADateHere_AnAlphaNumericStringHere”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM