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

silverlight组件位置的CSS问题。无法设置我想要的高度

  •  1
  • Ievgen  · 技术社区  · 14 年前

    页面必须包含:

    1. 横幅顶部空间(html)
    2. 中心-silverlight组件。他会伸到菲特佩奇。
    3. 横幅底部空间(html)

    看起来很简单,但我面临的问题与internet explorer 8。 Silverlight组件体积小,不拉伸。在其他浏览器中,它运行良好。

    <style type="text/css">
        html, body
        {
            height: 100%;
            overflow: auto;
        }
        body
        {
            padding: 0;
            margin: 0;
        }
        #silverlightControlHost
        {
            height: 100%;
            text-align: center;
        }
    </style>
    

    HTML格式:

    <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" style="overflow: hidden;
        height: 100%; width: 100%;">
        <table  frame="none" cellpadding="0" cellspacing="0" style="height: 100%; width: 100%; border:0px solid White;
            padding: 0px;">
            <tr style="background-color: Red; height: 30px; width: 100%;">
                <td>
                </td>
            </tr>
            <tr style="background-color: Blue; height: 100%; width: 100%;">
                <td>
                    <div id="silverlightControlHost" style="height: 100%; width: 100%; background-color: Black;">
                                  <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
                        width="100%" height="100%">
                        <param name="source" value="ClientBin/test.xap" />
                        <param name="onError" value="onSilverlightError" />
                        <param name="background" value="white" />
                        <param name="minRuntimeVersion" value="4.0.50401.0" />
                        <param name="autoUpgrade" value="true" />
                        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration: none">
                            <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Получить Microsoft Silverlight"
                                style="border-style: none" />
                        </a>
                    </object>
                    <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px;
                        border: 0px"></iframe>
                    </div>
                </td>
            </tr>
            <tr style="background-color: Red; height: 30px; width: 100%;">
                <td>
                </td>
            </tr>
        </table>
    </body>
    

    alt text

    IE8(不太好):

    alt text

    怎么了?如何修复?

    1 回复  |  直到 14 年前
        1
  •  2
  •   almog.ori    14 年前

    我不使用表格来布局,但那只是我:)

    <div id="container">
        <div id="top">
        </div>
        <div id="silverlightControlHost">
            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
                width="100%" height="100%">
                <param name="source" value="ClientBin/SilverlightApplication1.xap" />
                <param name="onError" value="onSilverlightError" />
                <param name="background" value="white" />
                <param name="minRuntimeVersion" value="4.0.50826.0" />
                <param name="autoUpgrade" value="true" />
            </object>
            <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe>
        </div>
        <div id="bottom">
        </div>
    </div>
    

    您需要做的是在silverlightControlHost类中将position切换到absolute,并将控件对齐以延伸到页面上,在html div容器的顶部和底部留出空间,例如

    #silverlightControlHost 
    {
        position: absolute;
        top:30px;
        bottom:30px;
        left:0px;
        right:0px;
        text-align:center;
    }
    

    下面是其他div的css类

    #top
    {
       height:30px;
       width:100%;
    }
    
    #bottom{
       height:30px; 
       width:100%;
       bottom:0px;
       position:absolute;
    } 
    
    #container
    { 
        height: 100%;
        width:100%;
    }
    

    希望有帮助

    编辑

    #bottom{
       height:30px; 
       width:100%;
       bottom:0px;
       position:absolute;
    }