I\'m trying to wrap a long word. I have seen this post : How to prevent long words from breaking my div?
It works great in a simple case like this :
.wra
I think this is what you are looking for.
WORKING DEMO
The HTML:
<!-- This wraps correctly -->
<div style="width:145px;">
<div class="wrapWords" style="width:100%;">
<a href="#">AAAAAAAAAAAAAAAAAA</a>
</div>
<div>
<!-- This doesn't work -->
<table style="width:100%;">
<tr>
<td style="width:145px;">
<table style="width:100%;">
<tr>
<td style="width:130px;">
<div class="wrapWords" style="width:inherit; display:inline-block;">
<a href="#">BBBBBBBBBBBBBBBBBB</a>
</div>
</td>
<td>
</td>
</tr>
</table>
</td>
<td>
</td>
</tr>
</table>
The Logic:
The div
and td
have different display
characteristics. You need to make your div
which is nested inside the td
to change its display
to, for instance here inline-block
with a fixed width
to achive what you are looking for.
Hope this helps.
There are 2 completely different algorithms for table layout: with or without table-layout: fixed
Former will adapt width of cells to the author's will
Latter will adapt width of cells to the content (the relative quantity/width/whatever of content in cells)
table is taking the table-layout: auto;
by default so as per contents increase the width also increases so you need to set table-layout to fixed.
table{
table-layout: fixed;
}
demo