iFrame Height Auto (CSS)

后端 未结 8 1930
无人共我
无人共我 2020-12-08 09:54

I am having problems with my iframe. I really want the frame to auto adjust heights according to the content within the iframe. I really want to do this via the CSS without

相关标签:
8条回答
  • 2020-12-08 10:26

    You should note that div tag behaves like nothing and just let you to put something in it. It means that if you insert a paragraph with 100 lines of text within a div tag, it shows all the text but its height won't change to contain all the text.

    So you have to use a CSS & HTML trick to handle this issue. This trick is very simple. you must use an empty div tag with class="clear" and then you will have to add this class to your CSS. Also note that your have #wrap in your CSS file but you don't have any tag with this id. In summary you have to change you code to something like below:

    HTML Code:

        <!-- Change "id" from "container" to "wrap" -->
        <div id="wrap">    
            <div id="header">
            </div>
    
            <div id="navigation"> 
                <a href="/" class="navigation">home</a>
                <a href="about.php" class="navigation">about</a>
                <a href="fanlisting.php" class="navigation">fanlisting</a>
                <a href="reasons.php" class="navigation">100 reasons</a>
                <a href="letter.php" class="navigation">letter</a>
            </div>
            <div id="content" >
                <h1>Update Information</h1>
                <iframe name="frame" id="frame" src="http://website.org/update.php" allowtransparency="true" frameborder="0"></iframe>
    
                <!-- Add this line -->
                <div class="clear"></div>
            </div>
            <div id="footer">
            </div>
    
            <!-- Add this line -->
            <div class="clear"></div>
        </div>
    

    And also add this line to your CSS file:

    .clear{ display: block; clear: both;}
    
    0 讨论(0)
  • 2020-12-08 10:29
     <div id="content" >
        <h1>Update Information</h1>
        <div id="support-box">
            <div id="wrapper">
                <iframe name="frame" id="frame" src="http://website.org/update.php" allowtransparency="true" frameborder="0"></iframe>
            </div>
        </div>
      </div>
     #support-box {
            width: 50%;
            float: left;
            display: block;
            height: 20rem; /* is support box height you can change as per your requirement*/
            background-color:#000;
        }
        #wrapper {
            width: 90%;
            display: block;
            position: relative;
            top: 50%;
            transform: translateY(-50%);
             background:#ffffd;
           margin:auto;
           height:100px; /* here the height values are automatic you can leave this if you can*/
    
        }
        #wrapper iframe {
            width: 100%;
            display: block;
            padding:10px;
            margin:auto;
        }
    

    https://jsfiddle.net/umd2ahce/1/

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