文本从div溢出

时间:2012-10-12 10:53:57

标签: css overflow

我希望主div的静态宽度为300px。但是当任何用户从Word程序中复制和粘贴文本时,则从div更改表格宽度和溢出文本。但我的网站宽度必须最大300px。我该如何解决这个问题?

<html>
<head>
<style>
#main td{
max-width:300px;
}

#main table{
max-width:300px;
}

</style>
</head>

<body>
<div id="main">
<table width="700" border="1">
<tr>
<td width="800"><p width="900">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
</tr>

<tr>
<td width="800"><p with="900">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></td>
</tr>
</table>
</div>
</body>
</html> 

2 个答案:

答案 0 :(得分:0)

更改

#main table{
max-width:300px;
}

#main *{
max-width:300px;
}

这样,TD,img和其他人仍然会被调整大小。此外,您可以在overflow-x:hidden div上使用#main来隐藏太大而无法容纳的内容。

答案 1 :(得分:0)

我建议在Word文本上进行某种类型的卫生操作,以删除不需要的内联样式。无论如何,你应该始终清理从文字传到网上的文字。你可以使用tinyIMCE或类似的东西。这样你就不用担心他们复制了什么,它总会服从CSS。