【问题标题】:css issue taking parent dimesion using %使用 % 获取父维度的 css 问题
【发布时间】:2014-11-27 12:13:46
【问题描述】:

我在使用 % 中的高度和宽度来获取父窗口的大小时遇到​​问题 见以下链接:http://liveweave.com/GZP43q

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

HTML 代码

<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;
}

【问题讨论】:

    标签: html css twitter-fabric


    【解决方案1】:

    当您在 CSS 中使用 % 时,它始终与父级高度/宽度相关。因此,您需要为所有父元素添加高度。对于contentwrapheight,以及widthheightbodyhtml

    【讨论】:

    • 我已经添加了 width ,但它仍然无法正常工作,请更新代码以提供解决方案
    猜你喜欢
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    相关资源
    最近更新 更多