CSS/HTML5 equivilent to iframe marginheight and marginwidth

后端 未结 3 1532
暖寄归人
暖寄归人 2021-01-18 01:32

I am doing a website layout for a company who uses IDevAdManager for rotating ads on their site. Unfortunately, I am not much of an expert in that field, so I can\'t give m

相关标签:
3条回答
  • 2021-01-18 01:44

    To be HTML5 valid the document inside the iframe has to get the correct style, not the iframe itself. I don't know that adManager thing but it depends on how the iframe is created.

    If it is dynamic and sameorigin you can enter it by

    document.getElementById("SomeIframe").contentDocument;
    

    and set margin by style to 0.

    let myFrameBody = document.getElementById("SomeIframe").contentDocument.querySelector('body');
    myFrameBody.style.margin = 0;
    

    If it is not sameorigin the owner of the document has to set this by himself, and that is never a bad idea, and also regarding HTML4.1 this would be considered valid.

    0 讨论(0)
  • 2021-01-18 01:46

    Bit late to the party, but using css to set the padding of the iframe ought to do the trick.

    0 讨论(0)
  • 2021-01-18 01:53

    Actually this is a valid question. Unfortunately it turns out that the marginheight, marginwidth and frameborder are properties of the iframe element itself, not the element's style property see http://www.w3schools.com/jsref/prop_frame_marginheight.asp

    So, for example, you can do this in JavaScript:-

    document.getElementById("SomeIframe").marginheight = "0";
    

    but you CANNOT do this

    document.getElementById("SomeIframe").style.marginheight = "0";
    

    and setting the margin has NO EFFECT (i.e. you will still get the default margin in the iframe element):-

    document.getElementById("SomeIframe").style.margin = "0";
    

    So the answer to cbright6062's question is that there is no way to set the marginheight, marginwidth and frameborder properties of an iframe in a style sheet.

    0 讨论(0)
提交回复
热议问题