如何在 <td> 中显示一行文本

pet*_*ter 2 html javascript css jquery

在我的 html 中,我将表格列设置为 35%。我想在 中显示一行文本<td>,任何超出列宽的字符都会被砍掉。我尝试使用text-overflow:clip. 但是如果<br>文本中有,它会显示多行。

我测试了我得到的答案。它似乎不起作用。我认为唯一的方法是在显示之前剪切文本。

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("div .test").css("background-color","yellow");
  $("div .test").css("text-overflow","clip");
  $("div .test").css("white-space","nowrap");
  $(".test br").css("display", "none");
//  $("div .test").css("overflow":"hidden");

});
</script>
</head>
<body>    

<table>
<tr>
<td>testing</td>
<td>
<div style="border:1px solid black;padding:10px;">
<p class="test">This is a paragraph.</p>
<span class="test">Skin or subcutaneous tissue or mucous membrane,repair of wound, other than wound closure at time of surgery, on face or neck,more > 7cm.</span>
</div>
</td>
</tr>
</table>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

谢谢你。

And*_*rew 5

听起来您不希望文本换行,而是希望在列的边缘被切掉。

将此添加到您的td以获得该效果:

white-space: nowrap;
overflow:hidden;
Run Code Online (Sandbox Code Playgroud)

见:http : //jsfiddle.net/3948a/1/