HTML表格宽度百分比,表格行平均分隔 [英] HTML Table width in percentage, table rows separated equally

查看:5468
本文介绍了HTML表格宽度百分比,表格行平均分隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在html中创建一个表格时,宽度为100%的表格,如果我希望所有单元格(tds)被分成相等部分,是否必须为每个单元格输入宽度%?我是否有义务这样做?

When I create a table in html, a table with a width of 100%, if I want all the cells (tds) to be divided in equal parts, do I have to enter the width % for each cell? Am I "obliged" to do it?

例如:

E.g.:

<table cellpadding="0" cellspacing="0" width="100%" border="0">
   <tr>
      <td width="25%"></td>
      <td width="25%"></td>
      <td width="25%"></td>
      <td width="25%"></td>
   </tr>
</table>

或者以下内容也可以是正确的程序,如果我想要在每个tds中不写宽度它们中的每一个均等分配:

OR the following could also be the right procedure, not to write the width in each tds if I want each of them to be devided equally:

<table cellpadding="0" cellspacing="0" width="100%" border="0">
   <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
   </tr>
</table>

我知道它适用于两种方式,但我只想知道合法的方式来做到这一点。

I know it works with both manners but I just want to know the "legit" way to do it.

推荐答案

您需要输入每个单元格的宽度。但是,等一下,还有一种更好的方法可以做到,那就是CSS:

You need to enter the width % for each cell. But wait, there's a better way to do that, it's called CSS:

<style>
     .equalDivide tr td { width:25%; }
</style>

<table class="equalDivide" cellpadding="0" cellspacing="0" width="100%" border="0">
   <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
   </tr>
</table>

这篇关于HTML表格宽度百分比,表格行平均分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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