简体   繁体   English

50%浸入容器中

[英]Div 50% inside a container

Can we somehow set up height:50% for a div that is situated inside a container (preferebly a table cell)? 我们能否以某种方式为位于容器(最好是表格单元)内的div设置height:50%

The dimensions of which we do not know and they may change a lot dynamically. 我们不知道其尺寸,并且它们可能会动态变化很多。

You can set up height for a div however parent elements must have their height set explicitly also. 您可以为div设置高度,但是父元素的高度也必须明确设置。 For example: 例如:

<html>
<head>
</head>
  <body style="height:100%">
    <table style="height:100%">
      <tr>
        <td style="height:100%">
          <div style="height:50%">
          </div>
        </td>
      </tr>
    </table>
  </body>
</html>

So doesn't matter that container height changes dynamically, so long as it is set. 因此,只要设置了容器高度,容器高度就不会动态变化。 There's other methods, this is probably the simplest. 还有其他方法,这可能是最简单的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM