Remove the Extra Whitespace Surrounding Iframes?

后端 未结 10 581
花落未央
花落未央 2021-02-02 05:55

I am using iframes in my page, and have stumbled across a weird issue. I set the iframe css like so

iframe {
    margin: none;
    padding: none;
    background:         


        
相关标签:
10条回答
  • 2021-02-02 06:17

    Maybe that whitespace is actually the outside margin of the document loaded in the . Try styling the loaded document (CSS styling the source page) with:

    html, body {
      border: 0px;
      margin: 0px;
      padding: 0px;
    }
    

    quoted from stackoverflow.com Here

    0 讨论(0)
  • 2021-02-02 06:18
    iframe { display:block; }
    

    iframe is a inline element

    0 讨论(0)
  • 2021-02-02 06:24

    Try html, body {margin:0px;}

    0 讨论(0)
  • 2021-02-02 06:26

    When you are using an inline element, the whitespace might be from the "line" the element is part of (ie. the space below the baseline). The solution then is to add this to its parent element.

    line-height: 0;
    
    0 讨论(0)
  • 2021-02-02 06:26

    Since none of the given answers provided a solution for me (I also stumbled across the weird margin issue when implementing an iFrame) I found this to be working fine:

    <iframe frameborder="0" marginwidth="0" marginheight="0" src="/something"></iframe>
    

    marginwidth and marginheight are not valid / officially supported HTML5-tags but they work just fine in my tests...

    0 讨论(0)
  • 2021-02-02 06:29

    try using a div with overflow: hidden; surrounding the <iframe>, like

    <div style="height: 29px; overflow: hidden;">
       <iframe frameborder=0 allowtransparency=yes scrolling=no src="../hng_frames/copyright_part.html" width="980" height="30">
          <p>Your browser does not support iframes.</p>
       </iframe>
    </div>
    
    0 讨论(0)
提交回复
热议问题