Patrick Gregorio Patrick Gregorio - 5 months ago 25
CSS Question

Prevent Element from Expanding

I have a table which has a column for URLs and sometimes the URL can get pretty long.

I set the table to have a specific width but there are times when the URL wouldn't even break itself and expand the table which messes up with the layout.

Here's a Fiddle for you to take a look at and I'll provide the codes below:

HTML



<table border="1">
<thead>
<tr>
<th>Name</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test</td>
<td>http://www.exampledomain.org/How-We-Work/General-Information/General-Opportunities/Open-Concept-Memo-Global-Test-Cases</td>
</tr>
</tbody>
</table>

<table border="1">
<thead>
<tr>
<th>Name</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr>
<td>Another Test</td>
<td>http://www.exampledomain.org/search?q=flagship+collaborative+research+program&btnG=Google%2BSearch&client=csiro_frontend&output=xml_no_dtd&proxystylesheet=csiro_frontend&proxyreload=0&sort=date%253AD%253AL%253Ad1&wc=200&wc_mc=1&oe=UTF-8&ie=UTF-8&ud=1&exclude_apps=1&site=Main&filter=0&getfields=*&sourcepage={CB41B120-BEE8-4511-9BED-A5E43D32381D}</td>
</tr>
</tbody>
</table>


CSS



table {
width: 500px;
margin: 5px;
}

Answer

https://jsfiddle.net/0xyhz7p0/1/

td {
   word-break: break-word;
}
Comments