我可以创建一个HTML表格宽度百分比高度,但像素精确行高度? [英] Can I create a HTML table width a percentage height but pixel accurate row heights?

查看:263
本文介绍了我可以创建一个HTML表格宽度百分比高度,但像素精确行高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在有两行的网页中创建一个表。该表需要填充整个页面,所以我已经将CSS的样式表中的表的高度和宽度设置为100%,HTML和body的高度也设置为100%。

I need to create a table in a web page that has two rows. The table needs to fill the entire page so I have set the height and width of the table to 100% in the CSS stylesheet and the height of the html and body to 100% too.

但是,我需要将表的顶行精确地设置为100像素的高度,第二行要展开以适应表的其余部分。当我设置顶行的高度时,它不工作。

However, I need to top row of the table to be exactly 100 pixels in height and the second row to expand to fit the remainder of the table. When I set the height of the top row, it doesn't work.

这种行为可能吗?我尝试了以下操作但不起作用。

Is this behaviour possible? I tried the following but it doesn't work.

                <table style="border-collapse:collapse;height:100%;width:100%;">
                    <tr>
                        <td style="border:solid 1px black;height:100px">1</td>
                        <td style="border:solid 1px black">2</td>
                    </tr>
                    <tr>
                        <td style="border:solid 1px black">3</td>
                        <td style="border:solid 1px black">4</td>
                    </tr>
                </table>



编辑:我使用表格数据,特别想使用表,而不是div。上面的示例是为了简化大约20列的表。

I am using tabular data and specifically want to use a table, not divs. The sample above is to simplify a table with around 20 columns.

编辑2:我发现了问题。它是HTML中的doctype定义(由Visual Studio添加)。删除...

Edit 2: I have found the issue. It is the doctype definition in the HTML (added by Visual Studio). After removing...

...完美无缺。所以我的新问题是,这是可行的,还是有正确的方法来做它与DOCTYPE?

...it works perfectly. So my new question is, is this OK to do or is there a correct way to do it with the DOCTYPE?

推荐答案

没有CSS,这是有效的:

Without CSS this works:

<html>
  <body>
    <table height="100%" width="100%" border="1">
      <tr height="100">
        <td>This is item text.</td>
      </tr>

      <tr>
        <td>This is item text 2.</td>
      </tr>
    </table>
  </body>
</html>

所以这是可能的,我现在可以尝试用CSS。

So it is possible, I'll try it now with CSS.

这篇关于我可以创建一个HTML表格宽度百分比高度,但像素精确行高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆