0

我在使用百分比中的高度和宽度来获取父窗口的大小时遇到​​问题,请参见下面的链接: http: //liveweave.com/GZP43q

我错过了什么,如何使它工作如何使画布与父宽度的宽度匹配,我找不到如何解决它,认为有点棘手的 css 问题

代码

<script src="http://fabricjs.com/lib/fabric.js"></script>

<div class="wrap">
<table align="center" width="100%" border="1">
<tr valign="top">
<td width="10%">
left
</td><td width="80%">
            <div id="content">
              <table border="1" width="100%">
                <tr><td style="border:1px solid red">
                    <canvas id="canvas" width="100%" height="100%">
                    </canvas>
                <div id="canvas-drop-area"></div>
                </td></tr>
              <tr><td style="border:1px solid red">
                    <canvas id="canvas1" width="320" height="256">
                    </canvas>
                <div id="canvas-drop-area1"></div>  
                </td></tr>              
            </table>
            </div>
</td><td width="10%">
right
</td></tr>
</table>
</div>

CSS 代码:

.wrap{
    margin: 0 auto;
    width: 400px;
}
#content{
    float:left;width: 100%;
}
#canvas{
    width:100%;
    height:100%;
    overflow:hidden;
    float:left;
    border:1px solid #000000;
}
#canvas1{
    width:320px;
    height:256px;
    overflow:hidden;
    float:left;
    border:1px solid #000000;
    background-color: yellow;
}
4

1 回答 1

0

当您%在 css 中使用时,它总是与父高度/宽度相关。因此,您需要为所有父元素添加高度。对于contentwrap一个heightwidthheightbodyhtml.

于 2014-11-27T12:16:39.387 回答