Why isn't my td wraping its content - css

I have a table cell that keep resisting to wrap it contents (a span). Here is the escenario according to Chrome dev tools:
The <td> has the following rules:
overflow:visible;
white-space:normal;
The <table> has:
table-layout:fixed;
First row in the table has two columns with fixed width defined; the problematic cell has padding="2".
From my knowledge that should do, but it is not wraping the contents. I have tried unsuccessfully with the following rules:
word-break: break-all;
word-wrap: break-word;
max-width: 120px; /*this is the max width I want to ensure*/
What am I missing here?

I don't know exactly how is your code because you didn't post it, but I followed your instructions and it worked for me.
See it here: http://jsfiddle.net/FJ7dB/
HTML:
<table>
<tr>
<td>TD-1-1</td>
<td padding="2">
<span>TD-1-2 ContentContentContentContentContentContentContentContentContentContentContentContentContentContentContentContentContent</span>
</td>
</tr>
<tr>
<td>TD-2-1</td>
<td>TD-2-2</td>
</tr>
</table>
CSS:
table{
table-layout:fixed;
border:1px solid blue;
}
td{
width:120px;
max-width:120px;
word-break: break-all;
word-wrap: break-word;
border:1px solid red;
}
What makes it work is max-width, which you said it was unsuccessful.
And it isn't necessary to set
overflow:visible;
white-space:normal;
because visible and normal are their default values.

Related

How can I keep the rightmost instead of leftmost contents of a TD?

I have a TD with contents often wider than the TD, a text-align of right, and an overflow-x of hidden. It is displaying the leftmost portion of its contents.
Let us say for the sake of argument that the cell content is "ABCDEFGHIJKLMNOPQRSTUVWXYZ", and the TD will show exactly six characters with a hidden overflow-x.
It is now showing "ABCDEF".
How can I show "UVWXYZ"?
You can use direction: rtl.
td {
border: 1px solid black;
max-width: 70px;
overflow-x: hidden;
direction: rtl;
/*text-align: right;*/
}
<table>
<tr>
<td>ABC</td>
<td>ABCDEFGHIJKLMNOPQRSTUVWXYZ</td>
</tr>
</table>

td {position:relative; left} does not move the border

Please see the following example:
http://jsfiddle.net/6t6hq/7/
when I use td with position relative to move it,
it only move the content but not the border.
How can I move the border with the content?
<table>
<tr>
<td id="relativeTD">1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
<div id="expected">expected</div>​
<style>
td{
border:1px solid #000;
min-width:100px;
}
#relativeTD{
position:relative;
left:60px;
}
#expected{
border:1px solid #000;
position:relative;
left:60px;
}​
</style>
TD is of display: table-cell;!
So you can't move it using relative positioning. Instead, create another <div> inside the <td> and give border and stuff.
Instead, give position: absolute for the td. It works! Also, you need to give position: relative to the table.
Fiddle: http://jsfiddle.net/6t6hq/9/
Else, you can use margin-left too to the td.
You cannot move a single td border you need to move the whole table
Demo
table {
margin-left: 60px;
}
Either what you can do is give your table border: 0;, place a div inside your td
give it some width, border and position: relative with left: 60px; and you are good to go

Table column text-overflow ellipsis ( width in % )

I have this markup for mobile.
<table>
<tr>
<td style="width:60%">
<div class="ellipsis">
Test bla bla
</div>
</td>
<td style="width:40%">
</td>
</tr>
CSS
.ellipsis {
width : 100%;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
word-break: break-all;
word-wrap: break-word;
}
The truncation doesn't work as desired, instead the column expands depending on content.
Table-Layout : fixed makes both the columns equal.
Any suggestions ? Thanks.
Please use the following css to make css3 truncation work with tables
table {
width: 200px; /*specify a width*/
table-layout:fixed;
}
The property "table-layout:fixed" seems important to work text truncation for any block level elements inside a table.

Align contents of DIV always on one line

I have the following :
HTML
<th class="sort">
<div>
<div class="sort"></div>Last Name
</div>
</th>
css:
table.tablesorter thead th.sort
{
padding:0;
}
table.tablesorter thead th div.sort
{
margin:0;
width:15px;
height:30px;
float:left;
background: url("/Content/images/admin/sort.png") no-repeat;
background-position: 0px center;
cursor:pointer;
}
table.tablesorter thead tr th.sort a
{
cursor:pointer;
color:inherit;
vertical-align:middle;
float: left;
padding-top: 7px;
}
I want to display inner and inside vertically aligned middle and always on ONE line so that when a browser window is resized (small) it will not break and will not more underneath inner (which is what is happening now).
thanks
use the "display inline" command...
<div style="display:inline;float left;">First name</div>
<div style="display:inline;float right;">Last name</div>
Its not clear to me what "inner" and "inside" youre referring to (you mught want to update and elaborate a bit, as well as post the complete markup for the table) but it sounds like you basically want everything in the th to be in one continuous line regardless of avialable space. You can turn off the text from wrapping with whitespace: nowrap;. However your content is going to overflow the th because thats how table cells work, so you need to set overflow: hidden on something that wraps the text. Unless yo need more than one elemment inside the cells you dont need the float.
The markup might look like this:
<thead>
<th><div class="clip sort">First Name</th>
<th><div class="clip sort">Last Name</th>
</thead>
Whith the css like so:
.clip {width: 100%; overflow: hidden; whitespace: nowrap;}
th {vertical-align: middle; height: 30px;}

IE7: How to make TD float?

I want a set of <td>s to float left in IE7. They should break onto the next line if the window is too small.
CSS
table {
width: 100%;
}
td {
border: 1px solid red;
}
tr.f td {
width: 500px;
float: left;
}
HTML:
<table>
<tr class="f">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
This works in IE8 and Firefox, but not in IE7. What am I doing wrong?
Page rendering mode is "IE7 (Quirks)" or "IE7 (Standards)". I'm trying with IE8, though, trusting that IE7 rendering mode is what it says. "IE8 Compatibility View" is failing as well, only "IE8 Standards" gets it right.
I don't think this is possible the way you want.
When you apply the float to td elements [in FF/IE8[ they become anonymous table objects as per the CSS 2.1 spec. Essentially, they're no longer table cells, and these anonymous objects have a display type that is floatable.
IE7 doesn't follow this part of the spec, in fact, the display type of the cells cannot be altered at all, and objects with a display type of table-cell can't be floated.
If you absolutely need to use a table (instead of a ul/li) could you do something like this instead?
<style type="text/css" media="screen">`
table {
width: 100%;
}
.f {
border: 1px solid red;
float: left;
height: 10px;
width: 500px;
}
</style>
<table summary="yes">
<tr><td>
<span class="f">1</span>
<span class="f">2</span>
<span class="f">3</span>
</td></tr>
</table>
My best guess: IE7 and below have stricter table models and don't allow you to change the flow of table elements.

Resources