Iframe 100% height inside body with padding

前端 未结 4 550
梦如初夏
梦如初夏 2020-12-05 14:52

I have an iframe in my HTML document and I\'m having a bit of trouble.

I also have a URL bar (fixed position element) at the top of the page that should stay with th

4条回答
  •  有刺的猬
    2020-12-05 15:20

    Whilst you can't say ‘height: 100% minus some pixels’ in CSS, you can make the iframe 100% high, then push its top down using padding. Then you can take advantage of the CSS3 box-sizing property to make the padding get subtracted from the height.

    This:

    
    
        test
        
    
        
        
    foo

    Works on IE8, Moz, Op, Saf, Chrome. You'd have to carry on using a JavaScript fallback to make the extra scrollbar disappear for browsers that don't support box-sizing though (in particular IE up to 7).

提交回复
热议问题