Liquid resize behaviour for table without table-layout:fixed? - html

I really could use some help with some style issue I fail to get solved:
Scenario:
Inside a web application I have a table visualizing a list of entries. Two of the columns can take longer content, which is chopped for display using "overflow:hidden;"and applying a "text-overflow:ellipsis". The content of all table cells is wrapped into spans so that I can apply animations whilst populating the table. All fine.
Now I want to change the tables layout from its former fixed style to a more liquid behaviour.
Before I had fixed width settings for the table columns. For all except two columns I keep the fixed width, even for one of the ellipsis-style-chopped columns. The other one gets a width of 100%, so that the table consumes the whole available container, thus giving a liquid style ("always use whole screen"). The column shows its content plus some whitespace which is used to pad as required.
Desired behaviour:
I expect the table to shrink when the windows size is decreased. This should obviously happen by reducing the width of the column set to 100%, since it is the only one without a fixed length. That part works only as long as the cells content fits in. As soon as the window gets that narrow, that the content does not fit any more a scrollbar is applied by the browser. This is not what I want. Instead I want the ellipsis-style-rules to chop that cells content, so that the table actually gets smaller, maybe up to a min-width.
Test case:
HTML:
<div>
<table>
<tr>
  <td class="c1"><span class="ellipsis">Alfreds Futterkiste</span></td>
  <td class="c2"><span class="ellipsis">Maria Anders</span></td>
  <td class="c3"><span class="ellipsis">Germany</span></td>
</tr>
<tr>
  <td class="c1"><span class="ellipsis">Laughing Bacchus Winecellars</span></td>
  <td class="c2"><span class="ellipsis">Yoshi Tannamuri</span></td>
  <td class="c3"><span class="ellipsis">Canada</span></td>
</tr>
<tr class="alt">
  <td class="c1"><span class="ellipsis">Königlich Essen</span></td>
  <td class="c2"><span class="ellipsis">Philip Cramer</span></td>
  <td class="c3"><span class="ellipsis">Germany</span></td>
</tr>
</table>
</div>​
CSS:
table{table-layout:fixed;width:100%;border:solid gray 1px;}
/*table{table-layout:auto;width:100%;border:solid gray 1px;}*/
tr{}
td{}
td.c1{width:100%;}
td.c2{width:6em;}
td.c3{width:4em;}
/* formatting the clipped output */
.ellipsis{display:block;overflow:hidden;white-space:nowrap;text-overflow: ellipsis;width:inherit;}
/* just for the test case */
div{display:block;width:90%;margin:1em;background-color:silver;}
span{padding:2px;width:inherit;}
I prepared a fiddle with that test case for you to play around:
http://jsfiddle.net/UgYFs/3/
When you decrease the windows width (or the width of the left bottom "Result" compartment) you can see how things work. This is the behaviour that I want.
The problem: (thus this question...)
This only works with a "table-layout:fixed;". Makes some sense, however there are reasons that make this option unavailable: in the real application the tables rows are inserted dynamically. This does not work with a fixed layout, at least the optical result is quite different (which also makes sense). So if I like it or not, I think I have to go with a "table-style:table" (the default). You can switch to that in the CSS compartment by uncommenting the second line, thus changing the table-layout. You see that the behaviour changes.
My question:
Is there a way to combine both things:
to get the desired behaviour as described and demonstrated
to fill the table without a fixed layout (maybe switching the layout later) ?
Until now I failed to succeed. But I am just a bloody beginner in all this stylish web stuff...

Right, since no one had an idea I tried a different approach to what I was asking about were. I want to close this question, so I post the outcome, even if it is not a solution to what I asked here...
I succeeded to modify the rest of the app such that the way the table is filed dynamically works even when table-layout: fixed; is set. This allows me to use standard css table rules to keep that single column flexible in width but still limited in length because the whole tables width can be derived from the container now.

Related

HTML Tables break layout with latest Chrome Browser 44.0.2403.89

I came across a strange one today, which actually wasted a lot of my time, as I first thought it was some module that I upgraded on Drupal or some code change. In fact, it is related to Google Chrome's browser update.
Currently Google Chrome's latest version is 44.0.2403.89. The previous version I was running was 43.0.2357.132. Tables on my site were displaying just fine. And actually, after hours of troubleshooting, I thought to just check the website with Safari and sure enough things were displaying as they always have. Then I checked Firefox, also no problem and displayed as it had. So it seems Google has changed something in Chrome to cause tables to break. Any idea what's going on and how I can fix it, or is this a bug with the latest Chrome version?
Here is a sample of the table being broken by Chrome:
http://www.yoninja.com/jp/browse/results/taxonomy%3A74
See how the middle column's table flows under the right side bar. If you check this page with the previous version of Chrome (43.0.2357.132), it displays just fine. Also displays perfect in Safari and Firefox's latest version. What gives?!?
* UPDATE *
So I have temporarily fixed it by using Drupal's View Theming and modifying the views-view-table--(viewname).tpl.php file and editing the column width of the column which holds the long text. Even specifying the table width, whether with a percentage or a specific width in pixels, doesn't work in the latest Google Chrome.
<table class="<?php print $class; ?>"<?php print $attributes; ?> style="width:770px;">
<table class="<?php print $class; ?>"<?php print $attributes; ?> style="width:100%;">
Neither of these work, specifying 100% doesn't change a thing. Specifying the width in pixels actually does change the width of the table but not the by the width you specify. Strange! Why would Google's update change the behavior of something that has already been working previously?
Anyway, the only way I have been able to get things working is by specifying the width of the column as mentioned below in one of the answers. However, I still feel this is unnecessary and it seems every other browser is still displaying tables properly. So the question is, will Google fix this?
Is there anyone I can get this working without having to specify the table width. I use this view in various pages, and I don't want to have to worry about specifying the width.
This has indeed been reported as a bug.
https://code.google.com/p/chromium/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=&id=512872
This bug seems to apply to tables who's width has been specified but rely on automatic width calculations on individual table divisions with larger amounts of text in them. It miscalculates the width table divisions which contain larger amounts of texts. Affected rows now extend beyond the edge of the table visually breaking column alignment.
Until a valid update to Chrome fixes this, you can apply my earlier posted work around.
You'll need to manually specify the width of table divisions which contain large amounts of text in them (not the table itself). This will override the invalid calculation and prevent your table row from expanding beyond the width of the table.
I've tested this with an inline width specifier on table divisions with large amounts of text in them.
<table>
<tr>
<td>
some stuff
</td>
<td width='30%'>
some other large text field whose width isn't calculated properly
</td>
</tr>
</table>
I too have experienced this issue. It does indeed seem to be an update from 43 to 44 that changed the layout behavior. My site used the automatic layout to re-size the width which no longer works well. The fix for our site was to set one of the larger text fields width with an inline width element on the table division.
Your mileage may vary.
<table>
<tr>
<td>
some stuff
</td>
<td width='30%'>
some other large text field whose width isn't calculated properly
</td>
</tr>
</table>
After the Chrome 44.0.2403.89 update pages containing an html table with a style of width:100% (or using bootstrap table classes) no longer honor the 100% width if ANY of the columns contains a "long" string (even if the string includes spaces). This is new behavior and I've confirmed it is directly related to the 44 update. Hopefully if enough people post it will get fixed.
I am having the same issue which broke our page layout.
However, I actually am using a fixed width CSS property on the table.
The width of the table is visibly larger than the width specified. (I.E., it overflows.)
Querying the width of the table with JS returns the CSS width set, not the real width.

Force page break at start of table, if too few lines on first page

I have some tables with print-reapeating thead and many rows. Sometimes a new table starts at the very bottom line of a page, when printing.
I want to force the table to do a page break, if the space left on the page is less than, say 10 cm.
I tried to put an (invisible) overlapping div before that table:
<div style="position:relative;">
<div style="position:abolute; top:0px; width:32px; height:10cm; overflow:visible; page-break-inside: avoid;"> </div>
</div>
<table goes here...>
But it's not working. (FF and IE11)
Is there any way to do that? (I'm trying to print a book, and the table is a new chapter).
I believe this is a bug in Chrome.
The code below demonstrates the best method I've found for multi-page table printing. It has the following features:
column headers repeat on each page
if a page break occurs near the top of the table, it will not leave behind an orphaned set of column headers (a problem which isn't limited to just Chrome)
page breaks occur only between rows
no need to worry about paper size or how many rows will fit-- the browser handles everything automatically
cell borders are always fully closed
the above 3 features apply whether or not the table has headers
works in Chrome!
... and the following known limitations:
doesn't support s (tfeet?)
only supports 1 (which is apparently the most you're allowed to have anyway).
only supports top-aligned
any CSS size values that affect height (including border-width and line-height) must be in px
table cannot (easily) be changed dynamically after the js has run
column widths cannot be set by applying width values to individual table cells; you should either let cell content automatically determine column width, or use s to set specific widths, if needed
I put two tables side by side: the left one (1px) only has a thead with 10cm height, the other contains the contents to print.
That sort of works.
I used float:left; for both tables, so they are side-by-side, but IE11 puts underneath.
Any better idea or an improvment of this approach?

Maximum width for table column

I tried to set the maximum width for a column in a table (that is, I would like all the cells in that column to have the same maximum width), however my initial attempt failed:
<table border="1">
<tr><td style="max-width:100px">a bunch of text here, it should get wrapped</td></tr>
<tr><td>a bunch of text here, it should get wrapped</td></tr>
</table>
(also at http://jsfiddle.net/Le6H6/4/ )
I was expecting that setting the maximum width for one cell should automatically set it for all the cells in the same column. But somehow the cell in the second row overrules the maximum width I set, and both cells are wider than that width now.
I have 2 questions:
Why is this happening?
I know that setting the max width on every cell in that column (either individually or through an appropriate CSS rule) will achieve what I wanted. But is there also a way to set the maximum width for the column without setting it for every one of those cells?
1) This is happening because this is how HTML tables work. The table re-sizes for the maximum cell width. It makes logical sense, if you think about it.
2) There are ways around this, but nothing that fits your constraints of adding a single style to a single cell.
Sorry if it's not the answer you're looking for. :/
You can't do that way because max-width can be applied on single cell. so u can use<div> to do it especially for that cell or make it for <table>
Try this :
<table border="1" style="max-width:100px;">
<tr>
<td>a bunch of text here, it should get wrapped</td>
</tr>
<tr>
<td>a bunch of text here, it should get wrapped</td>
</tr>
</table>
either use css
tr td { max-with :100px; }

How to make HTML table cell content to occupy all the cell rows?

I have this table - http://jsfiddle.net/mark69_fnd/cgwyJ/
Notice, the last column - Notes, it spans all the rows.
How can I make its content to occupy all the rows, rather than cause the table to be the width of the page?
I am looking for something like http://jsfiddle.net/mark69_fnd/cgwyJ/4/, only without resorting to the width css parameter.
EDIT
Exhibit A:
Exhibit B:
EDIT 2
I am not looking for a fixed width table. I just want the row spanning cell to utilize the vertical space efficiently.
Please, do not provide answers involving the width. If you think either width or <br/> are needed, then you can just reply with "Nope, that's impossible".
EDIT 3
OK, there is a great deal of confusion around my question. Probably, because it is not formulated clearly.
Of course, there is a width limit involved somewhere underneath, but it is not a constant. It cannot be baked into the CSS. This is because it is a function of the following parameters:
The height of the available vertical space (N)
The average height of the characters in the given font (A)
The length of the given text, when presented on a single line, again in the given font (B)
Given these parameters, the required width is A * B / N. So, there is a well defined way to formulate what I want, but you just cannot express it with a constant width. So, my question is this - are there means to achieve this declaratively (i.e. in HTML/CSS) using some other attributes/properties?
Hope this clarifies a bit the picture.
Either <br/> The Paragraph or just resort to the width: ; CSS Parameter, and Why wouldn't you want to do that?
but line breaking (<br/>) it all would be the only other option I can think of.
Honestly the CSS way is the best if you ask me, but you could always set the width to that paragraph cell, the problem with that is if there is too much text it will make the bottom row taller than the others.
http://jsfiddle.net/calder12/cgwyJ/6/
<html>
<body>
<table>
<thead>
<tr>
<th>Browser</th>
<th>http --> http</th>
<th>http --> https</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chrome</td>
<td>CORS</td>
<td>CORS (*)</td>
<td rowspan="3" width="280">If the SSL certificate validation fails, neither CORS nor JSONP will work. However, there is a workaround. The respective request .
</td>
</tr>
<tr>
<td>Firefox</td>
<td>CORS</td>
<td>CORS (*)</td>
</tr>

HTML table cell width - issue with heading globalization

I have the following table:
<table>
<tr>
<td width="10%">Heading1</td>
<td width="15%">Heading2</td>
....
<td width="5%">Heading3</td>
</tr>
....
</table>
the width of the cell is defined by the width of the first row's cells. So far, so good.
If I translate the headings to other language - the text in the cell changes its length and the result is bad looking table - some cell with a lot of space, while for others there is not enough such to display the text in them.
What should I do?
I have try so many different variations - with width - auto/percent/combination of them and nothing works.
Has anyone have an idea how to set the width in a way to work good with the context dynamically?
I think about some JavaScript function too - I can get the text of each heading before construction the html and according to its length to set the width of the table?
The width of the column is the same for all rows, you can't change this behavior. You can omit the width paramater, table will automatically adjust. You can try to set "min-width" css property if you do not want the columns to be too thin.