代码之家  ›  专栏  ›  技术社区  ›  Kamurai

如何使用百分比调整嵌入html对象的高度?

  •  0
  • Kamurai  · 技术社区  · 7 年前

    我正在尝试使用嵌入式html页面来模块化我的网页版本,只使用html和CSS。但是,对象web元素不响应CSS中的百分比。它们将响应vh,但这与嵌入HTML页面的内容无关。

    我用iframe玩了一点,也得到了同样的结果,我知道有媒体询问,但我还不能完全胜任。

    是否有方法按百分比设置对象(或等效嵌入对象)的高度,或者有其他方法根据嵌入页面的内容设置高度。

    Index.html:

    <!DOCTYPE HTML>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <link href="./Styles/Main.css" rel="stylesheet" type="text/css">
        </head>
        <body>
            <div id="idGeneralLayout">
                <header id="idHeaderRow">
                    <object data="./Universal/Logo.html">
                        Warning: Header could not be included!
                    </object>
                </header>
                <nav id="idNavigationBar">
                    <object data="./Universal/Navbar.html">
                        Warning: Navigation Bar could not be included!
                    </object>
                </nav>
                <div id="idCenterRow">
                    <div id="idCenterRowLeft">
                        <object class="classSectionHeader" data="./Universal/NavigationHeader.html">
                            Warning: Navigation Header could not be included!
                        </object>
                        <object class="classSectionContent" data="./Navigation.html">
                            Warning: Navigation could not be included!
                        </object>
                    </div>
                    <div id="idCenterRowMain">
                        <object data="./Content/Content_Index.html">
                            Warning: Content could not be included!
                        </object>
                    </div>
                    <div id="idCenterRowRight">
                        <object class="classSectionHeader" data="./Universal/InformationHeader.html">
                            Warning: Information Header could not be included!
                        </object>
                        <object class="classSectionContent" data="./Content/Versions_Index.html">
                            Warning: Versions could not be included!
                        </object>
                    </div>   
                </div>
                <footer id="idFooterRow">
                    <object data="./Universal/Footer.html">
                        Warning: Footer could not be included!
                    </object>
                </footer>
            </div>
        </body>
    </html>
    

    Logo.html:

    <!DOCTYPE HTML>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <link href="../Styles/Main.css" rel="stylesheet" type="text/css">
        </head>
        <body>
            <div id="idInnerLayout">
                <img id="idLogo" src="../Pictures/logoHTKB.jpg"><br>
            </div>
        </body>             
    </html>
    

    Main.css:(节略)

    object
    {
        width: 100%;
        height: auto !important;
        overflow: hidden;
    
        border: 0px solid #FE0101;
        vertical-align: top;
    }
    
    #idGeneralLayout
    {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
    
        background-color: #000000;
        border: 0px solid #FE0101;
        vertical-align: top;
    }
    
    #idInnerLayout
    {
        width: 100%;
        max-width: 100%;
        min-height: auto !important;
        max-height: 100%;
    
        background-color: #000000;
        border: 0px solid #FE0101;
        vertical-align: top;
    }
    
    #idHeaderRow
    {
        width: 100%;
        max-width: 100%;
        height: 44%;
        max-height: 44%;
        border: 0px solid #FE0101;
        vertical-align: top;
    }
    
    #idLogo
    {
        width: 100%;
        max-width: 100%;
        height: 50%;
        max-height: 50%;
    
        border: 0px solid #FE0101;
        vertical-align: top;
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   yinken    7 年前

    如果不使用一些脚本或其他脚本,则不能。就像iframe一样,对象无法“知道”其中内容的高度。

    有关使用iFrame和一些javascript的解决方案,请参见此处: Adjust width and height of iframe to fit with content in it