在HTML表格中隐藏以溢出为中心的文本

在HTML表格中隐藏以溢出为中心的文本,html,html-table,Html,Html Table,我在设置HTML的影响时遇到问题,该HTML包含一行居中文本,该行的宽度溢出。下面是我尝试过的一个例子,我得到了隐藏的文本,但只在行的右侧。有人能告诉我这是否可行吗 <div id="div1" style="display:inline; position: absolute; top:108px; left: 28px; width:403px; height:74px; background-color:transparent; z-index: 2; border: sol

我在设置HTML的影响时遇到问题,该HTML包含一行居中文本,该行的宽度溢出。下面是我尝试过的一个例子,我得到了隐藏的文本,但只在行的右侧。有人能告诉我这是否可行吗

    <div id="div1" style="display:inline; position: absolute; top:108px; left: 28px; width:403px; height:74px; background-color:transparent; z-index: 2; border: solid 0px #000000; color: #000000; ">
      <table width="100%" height="100%" cellpadding="0" cellspacing="0" style="color: #000000; font-family: Microsoft Sans Serif; font-size: 8.25pt; table-layout:fixed; ">
          <tr>
              <td id="tsp1" valign="middle" nowrap="nowrap"><div style="height:100%; text-align:center; overflow:hidden;">This is a test of the text subpanel wrapping capabilities or lack there of in the thick client versus the web client.</div></td>
          </tr>
      </table>
    </div>

这是对文本子面板包装功能的测试,或者是对厚客户端与web客户端之间缺乏包装功能的测试。
这是一种“脏”方法:

<html>
<head>
<title>Your Example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
    <!--
    function setCentered()
    {
        currString=$("#target").text();
        if(currString.length>16)
        {
            //magic equation
            amount=(currString.length-16);
            $("#target").css("margin-left","-"+amount.toString()+"px");
        }
    }
    // -->
</script>
<head>
<body onLoad="javascript:setCentered()">
    <div id="div1" style=" display:inline; position: absolute; top:108px; left: 28px; width:80px; height:74px; background-color:transparent; z-index: 2; border: solid 2px red; color: #000000; ">
        <table width="100%" height="100%" cellpadding="0" cellspacing="0" style="color: #000000; font-family: Microsoft Sans Serif; font-size: 8.25pt; table-layout:fixed; ">
            <tr>
                <td id="tsp1" valign="middle" nowrap="nowrap" style="text-align:center; overflow:hidden;"><p id="target">Space test #122 of totalling.</p></td>
            </tr>
        </table>
    </div>
</body>
</html>

你的榜样

空间测试#共122次


请记住,考虑到各种字体和显示设置,您必须改进js代码中的魔法方程式。

谢谢Gino,现在存在的问题是,我需要使用左对齐、右对齐和中对齐的能力。另外,我可以有一个或多个具有不同段落标记id的表,javascript必须考虑这些表。有什么想法吗?谢谢。关于理由,在等式中管理它们:例如,你可以做一个切换案例,针对每个不同的理由以不同的方式进行操作。在右JU的情况下,除非文本到达td标签的左侧,否则不要输入if。2。关于表id,在jQuery中,可以使用each()函数遍历整个页面的每个表,而不考虑id标记。另外,您可以始终通过jQuery向页面的每个td元素添加一个特殊的类标记(在运行时,jQuery),并使用它在js代码中标识td的标记。(.addClass())