我试图确定是否可能创建一个元素的CSS,该元素支持word-wrap:break-word
,但在不可能进行换行时也会扩展以占用其子元素的宽度。
<html>
<style>
.outer {
background-color:red;
word-wrap:break-word;
}
</style>
<div class="outer">
User generated content:
<a href="http://www.google.com">http://anannoyinglylongurlthatcausesthepagetogrowtolongunlessIusewordwrapbreakwordasdfasfasdfasdfasdfasdfasdfsadfasdfadsf</a>
<table>
<tr>
<td>asdfasdfadsffdsasdfasdfsadfafsd</td>
<td>asdfasdfadsffdaasdfassdffaafasds</td>
</tr>
</table>
<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png"/>
</div>
</html>
在上面的示例中,URL 可以正确地换行,但如果窗口变窄,则表格和图像会溢出红色外部 div。如果我将外部 div 设置为 display:inline-block 或 display:table,则红色外部 div 会正确扩展以包含内容,但是如果窗口比 URL 更窄,则 URL 不会换行。
我只需要在 WebKit(Android 上)中使其工作,并且如果可能,我正在尝试找到仅使用 CSS(无 JavaScript)的解决方案。