Removing Table Cell autoresize - html

How do to remove Auto Resize of Table cell? When I enter a text that would exceed the width of a table cell it automatically increases its width. Is there a way to disable its auto resize?
I'm directly adding text in table cell without any other element than <td>,
<td>Text is Here...</td>
Is there an element when the text exceeds the <td>'s width it will auto end line the next word. is that possible? I tried <p> and it doesn't work for me.
This is a sample:
http://jsfiddle.net/88RtG/2/
I want the first cell to have same width all the others regardless of its contents.

Browsers apparently expand a cell no matter what (even table-layout: fixed does not help), if the cell contains a string of characters that cannot be broken by the rules that the browser is applying.
If a string like “asdasdasdasdasdasddasdasdadasd” has no permissible breaking points, then it seems that the only way is to wrap the cell content in an element, say <td><div class=cell>...</div></td> and set a width on that inner element. You would then have to deal with the overflow issue (should the excess content flow into the next cell, or be hidden, or what?).
If it has permissible breaking points, mark them, using <wbr> or ​ (More info on this: http://www.cs.tut.fi/~jkorpela/html/nobr.html#suggest ) for simple line break opportunities, ­ for hyphenation points.

Specify the width to the table, row or the cell.

Try:
<td width="80px">Text is Here...</td>
Alter the width on all the cells of the ones you want - only need to do it on the first row. You can use percentages as well.

Related

How to do text wrapping inside a table with auto layout

I have a table with auto layout which has strings inside <td> and some of them may be long so i would prefer to wrap them to avoid too long horizontal display. I tried both apply the style to <td> or put <div> around the elements for this but couldn't get it to work properly. I observed the following:
In order to have any text wrapping at all, the white-space property has to be set to one of its wrapping values such as pre-wrap, normal, pre-line, etc. If instead white-space is set to any non-wrapping value such as pre, wrapping doesn't happen no matter what values i use for overflow-wrap or break-word properties. Even if i set max-width, the text just overflows.
If I set white-space to a wrapping value, such as pre-wrap, the wrapping happens but it wraps too much: I guess it tries to auto-size the column to its minimum possible width and then wraps accordingly. E.g. if the column header has only 2 characters, it wraps after each 2 characters and i see my strings broken into multiple lines 2-character long, which certainly does not look good. Note that my table does have a lot of columns, so maybe that's why it chooses to auto-size column width like this.
What I would prefer is to simply wrap after certain width is reached, but not before, e.g. start wrapping if it exceeds 30 characters. Is there a way to do this (short of breaking strings manually in code)? Note that i tried max-width but it didn't work as i mentioned above (depending on white-space value, it either overflows or starts wrapping at min possible width).
The only thing that did work, sort of, is setting min-width (together with the wrapping value of white-space property, in which case it didn't size the column or wrap to smaller than that value. However, this is not exactly what I want: some column values may be short and i don't want to create unnecessary space in this case. If the column values are short (such that no wrapping is needed) i would prefer to size to content (btw, i tried using min-content and fit-content, but it didn't work, still the same behavior).
Note that for an unrelated reason, setting table-layout to fixed is not an option for me.

How to force text go outside table cell without changing its size

I need to place a text with no spaces into left cell of my table, but I want to keep the size of the cell. Below is graphics example of what I want to achieve:
I tried different word-wrap settings but it only works for divs and not the cell table.
fix the size of left div with css using width.

Can't change width of table data element

I'm posting a screenshot of the element in question. You should be able to see, I am applying element-specific styling removing all margin, padding and setting the width to 0px. No matter what I do, this table data element is abnormally large. I want to significantly reduce its width, but it won't listen to me. I have the feeling this is some obscure HTML algorithm that I know nothing of but can't say. Any ideas?
Update: The answer was that HTML will make sure the table data elements take up the entire width of the table, no matter if you try to narrow individual elements (so in essence, it was some weird HTML algorithm or functionality). That said, I will accept the answer below because it is so thorough it should cover the other possible issues people may run into.
There is some obscurity to how the width of a table cell (<td>) is defined, as official documentation is unclear and allows some behavior to be defined by the browser. But here are a few characteristics that appear stable across the spectrum of browsers.
Managing the Width of HTML Table Cells <td>
Table with Single Cell
In a table that consists of a single cell – in other words, a table with one column and one row – where the width hasn't been explicitly defined in the <table> element, the width can be controlled directly by the <td> element.
This won't work (the td rule will be ignored):
table { width: 100%;}
td {width: 300px;}
The width: 300px fails because the <table> element has a defined width.
However, this will work:
/* table { width: 100%;} */
td {width: 300px;}
DEMO
Table Column with Multiple Cells
To set the width of a table cell in a column with multiple cells the entire column must be adjusted. Any widths assigned to the individual <td>s will be ignored. Simply adjust the width of the table to adjust the width of the <td>s in the column.
DEMO
Table with Multiple Columns and Multiple Rows
To set the width of a table with multiple columns and rows, the Table Column Element (<col>) is ideal because it targets individual columns.
DEMO
The problem described in the question involves a table cell that won't accept a shorter width assignment. The first realization here is that the table cell by default expands to fill 100% of the column width allotted (learn more about <td> default width). The way to reduce the width of this cell is described above.
HOWEVER, I suspect that in some cases the person wanting to reduce the width of a table cell is actually trying to reduce the width of the content inside the cell (like an image or a form input). In these cases, adjusting the table may be unnecessary. All that would be needed is to adjust the width of the content itself, or its container (div, span, figure, etc.).
In this image, the width of the table cells are at 100%, but the width of the input fields vary.
DEMO
colspan
If in fact the need is to reduce the width of a single cell within a column of multiple cells, then you may want to consider the colspan attribute. With colspan, columns can me merged making cells wider. Cells without colspan assigned will be shorter, and appear even shorter when their adjacent cells are hidden.
In this image, display: none has been applied to the bottom right cell of this 2-column table.
DEMO
So, in the case of your table cell that won't budge, consider adjusting the width of the <table> element (if it's a single column table), assign and adjust a <col> element (if it's a multi-column table), adjust the width of the content directly (if that's the only element you want adjusted), or use colspan.
Sorry I can't be more specific about the exact solution in your case. No code was provided for review. But hopefully one of these methods helps you out.

Force <td> to respect new width, or ignore previous width

I am working on cleaning up my companies newsletter emails. My issue is that I would like to force my <td> to respect the width that I specify rather than following the widths of the previous <td>. The other issue is that this needs to be very email client compatible.
Here's a jsfiddle of what I'm working on. http://jsfiddle.net/zwf0dL8r/ Sorry about the inline styles, aren't html emails great..
As you can see, the light grey areas are following the width of the first <td> which is holding the cpap.com logo.
Ideally, I wanted to be able to define the widths of <td>s to something new, each time I create a new <tbody>..
You could use CSS to force some behavior, but the browser or email client generally calculate the width of columns automatically based on content, using the widest specified width for the column when the content is shorter. To avoid this you can add the property table-layout: fixed; to the style of the table, but you will have to manually assign the correct widths for each column.
Tables with fixed layout are faster to display but don't resize according to content. The larger content overflows it's cell, causing an ugly looking overlapping data.
Take a look here for e-mail client compatibility: https://www.campaignmonitor.com/css/
Edit.:
To make the bellow cell take the space of the above cells you can add a colspan="numOfColsToTake".
What many people forget is that each <TD> define a column, not only an individual cell. Imagine you are designing it on Excel. If you would do this on Excel, you would have to use the merge cells option for the bellow cell to take the space of the 2 above. The colspan attribute of <TD> elements makes exactly this.
<td colspan="2"><p>Something</p></td>

how to add data to a table cell without affecting height of other cells

I have to add data to table cells dynamically. But when I add data to one cell, the height of all the other cells also increases. So, is there any way that the height of only that cell where data is added increases, rest remain same.
Also is there any way to insert only table cells beneath certain cells in a row without adding a new row?
embed the content in each cell within a DIV and enable overflow:auto on that div, so that a scroll bar appears if the height exceeds the maximum permitted.
<table><tr><td height="50"> Hello World!!</td></tr></table>
Put the height inside the td tag
Fundamental problem... tables are grids. You can merge cells (col/rowspan) but a line is always a line - which is to say you can't make a cell a different height to its neighbours by definition.
If you're trying to show data in a hierarchical way, use a hierarchical structure like <ul>/<li> and style it as appropriate (margins, etc...). If you need block elements, have each <li> wrap a <div>