Is it feasible to create CSS that allows an element to support word-wrap:break-word
, while also adjusting its width to fit the content when breaking is not possible?
<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>
In the provided example, the URL breaks correctly, but the table and image overflow the red outer div if the window width decreases.
Changing the outer div to display:inline-block or display:table causes it to adjust properly to accommodate the content, but the URL no longer breaks if the window is narrower than the URL.
This solution needs to be specific to WebKit (on Android) and should ideally be achieved through CSS only, without relying on Javascript.