I have designed a box in which the right side can grow vertically and I want the left side, which contains two elements one above the other one, to grow equally with it. After much struggling I have come up with a solution which I'm not sure is optimal.

我设计了一个盒子,右侧可以垂直生长,我希望左侧包含两个元素,一个在另一个之上,与它一样生长。经过多次努力,我想出了一个我不确定是最优的解决方案。

Here is the box: http://i.imgur.com/Hq2OrwN.png.

这是方框:http://i.imgur.com/Hq2OrwN.png。

Here is the solution I've come up with:

这是我提出的解决方案:

<table class="equalHeight" cellpadding="0" cellspacing="0">
<tr>
    <td colspan="2">Top Row</td>
</tr>
<tr>
    <td>
        <table class="rows" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td>TOP</td>
            </tr>
            <tr>
                <td>BOTTOM</td>
            </tr>
        </table>
    </td>
    <td id="questionTxt">Question
        <br>Question
        <br>Question
        <br>Question
        <br>Question
        <br>Question
        <br>Question
        <br>Question
        <br>
    </td>
</tr>
</table>


    .equalHeight {
    border-collapse: collapse;
    width:500px;
}
.equalHeight td {
    border:1px solid #CCC;
    height: 100%
}
.rows {
    border-collapse: collapse;
    width: 100%;
}
.rows td {
    text-align: center
}

    $(document).ready(function () {
    height = $("#questionTxt").height();
    rowHeight = height / 2;

    $(".rows").css("height", height);
    $(".rows td").css("height", rowHeight);
});

See it here: http://jsfiddle.net/joshmweinstein/2wjmj5nm/

在这里看到:http://jsfiddle.net/joshmweinstein/2wjmj5nm/

I've already seen one shortcoming which is that this solution does not allow for dynamic resizing of the page. But that is not an issue I am concerned with at the moment.

我已经看到一个缺点,即该解决方案不允许动态调整页面大小。但这不是我现在关注的问题。

One of the things I'm worried about is page performance. It is a very short js, but the box will be rendered 20-30 times on each page.

我担心的一件事是页面性能。这是一个非常短的js,但每个页面上的框将呈现20-30次。

Criticism and feedback are requested. Thanks.

要求提出批评和反馈。谢谢。

1 个解决方案

#1


0

Instead of jQuery you can use css

而不是jQuery你可以使用CSS

height:calc(100% / 2);

.equalHeight {
  border-collapse: collapse;
  width: 500px;
  height: intrinsic;
}
.equalHeight td {
  border: 1px solid #CCC;
  height: 100%
}
.rows {
  border-collapse: collapse;
  width: 100%;
  height: 100%;
}
.rows td {
  text-align: center;
  height: calc(100% / 2);
  border: 0;
}
.rows tr:first-child td {
  border-bottom: 1px solid #CCC;
}
<table class="equalHeight" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2">Top Row</td>
  </tr>
  <tr>
    <td>
      <table class="rows" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>TOP</td>
        </tr>
        <tr>
          <td>BOTTOM</td>
        </tr>
      </table>
    </td>
    <td id="questionTxt">Question
      <br/>Question
      <br/>Question</td>
  </tr>
</table>
<br>
<br>
<table class="equalHeight" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2">Top Row</td>
  </tr>
  <tr>
    <td>
      <table class="rows" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>TOP</td>
        </tr>
        <tr>
          <td>BOTTOM</td>
        </tr>
      </table>
    </td>
    <td id="questionTxt">Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question</td>
  </tr>
</table>
<br>
<br>
<table class="equalHeight" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2">Top Row</td>
  </tr>
  <tr>
    <td>
      <table class="rows" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>TOP</td>
        </tr>
        <tr>
          <td>BOTTOM</td>
        </tr>
      </table>
    </td>
    <td id="questionTxt">Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question
      <br/>Question</td>
  </tr>
</table>

更多相关文章

  1. 手机端阻止页面滑动
  2. golang写服务端程序,作为文件上传与下载的服务器。配合HTML5以网
  3. JSP 或HTML 如何通过button按钮转到想去的页面
  4. HTML5中window.postMessage,在两个页面之间的数据传递
  5. 在ios中,html5页面打电话
  6. 如何用DWR返回一个html页面?
  7. 在CSDN下载资源,扣了积分,下载的是一个404页面的html文件
  8. html5 canvas绘制圆形印章,以及与页面交互
  9. JSP页面图片路径为中文时乱码解决办法

随机推荐

  1. android快速开发框架afinal(数据库篇)
  2. Android(安卓)二维码 生成和识别(附Demo源
  3. 初识ClickHouse——安装与入门
  4. [置顶] Android的Activity屏幕切换动画(
  5. 面试官:为什么静态方法不能调用非静态方法
  6. Android(安卓)自动化测试—robotium(一)环
  7. android中下载文件到SD卡的方法
  8. linux搭建SVN服务器
  9. android中fitsSystemWindows的用处
  10. Android(安卓)sdk 安装及Adk安装