How does the DiggBar dynamically resize its iframe's height based on content not on their domain?

前端 未结 5 2146
南方客
南方客 2020-12-13 01:08

Someone has already asked, How does the DiggBar work? in a previous question.

While someone provided a decent answer it didn\'t address one thing:

5条回答
  •  一个人的身影
    2020-12-13 01:49

    If you look at their CSS, they use height: 100% for the iframe:

    iframe#diggiFrame {
        color: #666;
        width: 100%;
        height: 100%;
        z-index: 10;
        -webkit-box-sizing: border-box;    
    }
    

    They position the DiggBar above that with a height of 46px, so the iframe takes 100% of the remaining space. They use overflow: hidden on the body element to keep the iframe entirely within the vertical height of the page, rather than allowing the page to scroll. This means that the scroll bar will then appear inside the iframe, instead of for the whole page. Note that the the way the DiggBar does it works only in quirks mode in Firefox; see below for how to do it in standards mode.

    body {
        padding: 46px 0 0 0;
        margin: 0;
        background: #fff;
        overflow: hidden; 
        color: #333;
        text-align: left;
    }
    
    #t {
        width: 100%;
        min-width: 950px;
        height: 46px;
        z-index: 100;
        position: absolute;
        top: 0;
        left: 0;
        /* overflow: hidden; */
        border-bottom: 1px solid #666;
        background: #fff url(/App_PermaFrame/media/img/back.gif) repeat-x;
        line-height: 1;
    }
    

    edit: For those who don't believe me, here is a small example. To get it to fill the entire space, you need to set it to have no border, and you need to have no margins.

    edit 2: Ah, sorry, I see what you were talking about. You need the overflow: hidden on the body tag to get the scroll bar to work the way you want.

    edit 3: It looks like you have to be in quirks mode for this to work in Firefox; if you include a declaration, that puts you into standards mode, and your iframe comes out too small.

    edit 4: Ah, you can do it in standards mode in Firefox as well. Got the answer here. You need to set the height on your and elements to 100% as well. (Note that the is the doctype for HTML 5, which is a work in progress; however, it works on all modern browsers for turning on standards mode).

    
    
    
      
    
    
      

    This is my fake DiggBar

提交回复
热议问题