css - HTML div height is different when shown with and without an iframe -


i have chunk of html dynamically generated. show both directly in page , embed iframe. strange thing div block shown in 2 places has different height through styles same. code below , live result shown in codepen(http://codepen.io/anon/pen/bdkvqx). have ideas why happening? appreciated.

html content

<div class="height-diff" style="width: 198px; font-size: 30px;">   <span style="font-size:12px">     <span>barlett knit</span>   </span> </div> 

the same content above, inject iframe

var html = '<style>.height-diff {background-color: green;}</style>              <div class="height-diff" style="width: 198px; font-size: 30px;">                <span style="font-size:12px">                   <span>barlett knit</span>                </span>             </div>';  var doc = window.document; iframe = doc.createelement("iframe"), style = iframe.style;  iframe.setattribute("src", "about:blank"); iframe.setattribute("frameborder", "0"); iframe.setattribute("allowfullscreen", "true"); doc.body.appendchild(iframe);  var contentdocument = iframe.contentdocument;  contentdocument.open(); contentdocument.write(html); contentdocument.close(); 

updated answer: iframe html not have <doctype> declared , going quirks mode. see codepen doctype added. can't believe didn't notice earlier.

this appears happening because have not specified line-height. see codepen line-height added. seems rendering bug. appears white space being added before span in primary document not in iframe. strange height calculated correctly if add other characters around span or set span display:block;. edit: not strange, quirks mode.

<div class="height-diff" style="width: 198px; font-size: 30px;line-height:1.2em;">   &nbsp;       <span style="font-size:12px">     <span>barlett knit</span>   </span>   &nbsp;  </div> <br /> <div class="height-diff" style="width: 198px; font-size: 30px;line-height:1.2em;">   <span style="font-size:12px; display:block;">     <span style="display:block;">barlett knit</span>   </span> </div> 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -