Chrome does not respect display property on table elements - html

Is there any particular reason why chrome does not respect "display:inline" when it's used on "<table>" and is there a known workaround? Everything works fine in firefox but for some reason chrome refuses to do the right thing when I type
<table style="display:inline;">
table stuff
</table>
firefox alignment: firefox alignment http://dkarapet.userworld.com/cart_noDB/firefox_alignment.png
chrome alignment: chrome alignment http://dkarapet.userworld.com/cart_noDB/chrome_alignment.png
Both versions use the same html source that sets the display property to inline. The tables individually are not wrapped inside any other div and they are all enclosed inside one big div. Here's the pastie for the relevant part of the html.

Try inline-block.

css 2.1 defines inline-table. No idea how widely supported it is, but it sounds like that might be what you're looking for.
http://www.w3.org/TR/CSS21/tables.html#table-display
Although from your screenshot, it looks like what you really want is control over vertical alignment.

Why on earth would you set a table element to be inline? It should be a display of table. User error IMO.
You'd have to alter the display mode of all the tr and td elements inside otherwise they will improperly render, most likely.
If you need the table to be in the same line as another element, wrap a div around the table and float it. Don't mess with the table.
EDIT: As I specified per my last comment, you should mess with vertical-align and probably set it to top on the tables.

To pull of what you're after, you just need to add this to every td:
<td valign="top">
That will force everything to the top of each cell and will force things to display inline, how you want them to. No CSS needed here.
It SHOULD be coded like this:
<table>
<tr>
<td valign="top">item 1 info</td>
<td valign="top">item 2 info</td>
<td valign="top">item 3 info</td>
</tr>
<tr>
<td valign="top">item 4 info</td>
<td valign="top">item 5 info</td>
<td valign="top">item 6 info</td>
</tr>
</table>
edit: Or if (for some reason) you're not using TR and TD's you can try this:
<table style="vertical-align:top;">
table stuff
</table>

Related

Is there any way to have a tag between table-row and table-cell in a CSS table?

There can be no tag between <tr> and <td> in an HTML table. (Is there a tag for grouping "td" or "th" tags?) But is there any way to have such a grouping tag that between <div>s with display: table-row and display: table-cell?
This may seem silly, but the point is that I want to add behavior like #mouseover="doSomething" or :class="{someClass: someCondition}" in a Vue.js application, and I need a tag for that. I don't want to add behavior to the whole row, and to stay DRY I would rather not add it to each cell individually.
Edit: HTML does not offer a solution, but in Vue I was able to get the desired result using vue-fragment. It allows to attach behaviour to the dummy <fragment> tag. Example: MatrixRLabel in MatrixR (Those are the beige labels in the upper matrix in this app.)
display: table-row and display: table-cell applies a certain relationship to the parent and child divs. Just like with <tr> and <td>, adding a div "in between them" obviously disrupts this relationship, and causes results I cannot meaningfully predict without a bit of research.
So yes, you will have to apply the behavior to the desired cells individually.
<tr>
<td #mouseover="doSomething">...</td>
<td #mouseover="doSomething">...</td>
<td>...</td>
</tr>
Alternatively, you can identify those cells with a class and then have the behavior check for that class before executing.
<tr #mouseover="doSomething">
<td class="onlyToMe">...</td>
<td class="onlyToMe">...</td>
<td>...</td>
</tr>
Since you haven't gotten an answer before this, perhaps you've figured something out yourself? Do share if you can. Cheers!

CSS convert table columns into full-width stacked elements

I've found many ways to create a 'tableless' table layout using only DIVs, but very little about the opposite.
I have more than a few html pages with a table structure, and they all refer to a common CSS file. The tables have a simple 2-column layout as follows:
<table>
<tbody>
<tr>
<th>category</th>
<td>description</td>
</tr>
<tr>
<th>category</th>
<td>description</td>
</tr>
</tbody>
</table>
I want to be able to transform the layout of the table through CSS only, in order to make it look like a 'single-column table' if you will, with both categories and descriptions stacked on top of another within the full-width of the table. I've tried display:block and width:100% but it doesn't work cross-browser.
Thoughts?
You can achieve the result you want if you float each cell.
See this demo: http://jsfiddle.net/t3ZaM/
Works in FF, Chrome, Opera, Safari, IE9 and 10 but I can't check for older versions of IE because I don't have them.

How to make td (cell) from html table expand for the row to fit in one line?

In some html cells (td) the text is wrapped because the size of the column is smaller than the size of the text on the cell. I don't want the text to be wrapped, I want the column width to expand so the wrapping don't happen!
How can I do that?
One final note, I only can use html code, no css :(
Confusing question, but I think you might be looking for the colspan="x" attribute.
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td colspan="2">fills both columns</td>
</tr>
</table>
Since you can't use CSS, how about:
<td nowrap="nowrap">
I'd prefer to use CSS here on the TD (white-space:nowrap) since the nowrap attribute on the TD element isn't supported HTML 4.01 Strict / XHTML 1.0 Strict.
Here's a quick jsFiddle example showing the effect. Take out the attribute and you can see the difference.

Hiding table cells in safari 5?

What I am doing seems to work on firefox and IE but not safari.
I have something like this
<table>
<thead>
<tr>
<th style="display: none;">hi</th>
</tr>
</thead>
<tr class="someClass">
<td style="display: none;"><span>hi</span></td>
</tr>
Now imagine I have many columns and rows and many headers. Now in all browsers this coulmn would be hidden. In safari it makes some gap and then all the other columns are out of alignment.
http://gyazo.com/ef5ce5e994abb954aab7069b14699476.png
this is how my column headers look like. Am I missing something?
Setting display:none on an element takes it out of the document flow, but that doesn't always work well with table cells as they are not independent of the surrounding elements.
You would have to actually remove the elements from the table rather than hiding them to make the table realign itself with the remaining elements.
I think I figured it out. I just put that column last(and the header last as well). Now it seems to look proper.

Which is the better way of specifying HTML Fixed Column width (width or style attribute)

I would like to ask what is the better way of specifying HTML column width? the width attribute or the style attribute? Assuming I am using IE 6. Does IE render the width attribute better than style?
By width attribute
<table width="900">
<tr>
<td width="450">A</td>
<td colspan="2" width="450">B&C</td>
</tr>
....
</table>
OR by style attribute
<table style="width:900px;">
<tr>
<td style="width: 450px;">A</td>
<td colspan="2" style="width: 450px;">B&C</td>
</tr>
....
</table>
Firstly before I answer your question, something you should know is how tables are rendered, experiment with the table-layout fixed style for the table element:
If the browser knows the width of the first table row columns upfront (if you provide the table layout fixed style on the table) the browser can begin rendering the top of the table even before its calculated the width of any resulting rows. What this means? Tables populated by Ajax calls with a fixed layout can begin displaying results to a user before the full ajax call is finished. Best way to think of this is like a progressive jpg. In the end your pages will appear to load faster.
table
{
table-layout:fixed;
}
Now to answer your question.
Actually neither example you provided is correct. you typically do not set width on a cell that is spanned across 2 or more cells. In any table its a good idea to create at least 1 row with all the cells, this can either be in the TH or (just the way I like to do it in a blank tr.
For example...
<table>
<tr>
<td width="450"></td>
<td width="225"></td>
<td width="225"></td>
</tr>
<tr>
<td>content here</td>
<td colspan="2">content here</td>
</tr>
</table>
What ever way you decide to use style or just standard html width, the choice is yours, but in the end you should have your first row (if table layout is fixed) or any row (if table layout is not fixed) to contain the width definition for each invidivual cell. This will also help you with planning the correct looking table, hope this helps.
Test the table layout fixed, by creating a huge like 10 000 row table, and test the rendering speed vs a non fixed table layout.
The whole debate about HTML 4 vs XHTML , style vs attributes I think is really a question of maintainability. I don't think there is anything wrong setting the width using Style or plain width with HTML 4 transitional, they both do the same thing. The reason why you can do both is because HTML has evolved a bit, yes it can get messy! Good luck
Just add <div> tag inside <td> or <th> define width inside <div>. This will help you. Nothing else works.
eg.
<td><div style="width: 50px" >...............</div></td>