Hiding table cells in safari 5? - html

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.

Related

Cell next to rowspan cells height difference in Firefox and Chrome

I'm trying to build a table in HTML where there is one row with some generic information, followed by multiple rows of related detail data, followed by again a generic row, a set of detailed rows, etc.
The way I'm approaching it is that the cells in the generic row have a rowspan equal to the number of detail rows plus one. That way the detail rows get "pushed" to the right by the generic row.
The problem I have is when the generic row is higher than the detail row, for example because of multi-line contents, on Firefox the detail row gets a minimal height aligned to the bottom while on Chromium-based browsers the detail row has the same height as the generic row.
An example with just one detail row:
<table border="1">
<tr>
<td rowspan="2">left<br><br>1</td>
<td rowspan="2">left<br><br>2</td>
</tr>
<tr>
<td>right1</td>
</tr>
</table>
In Firefox it looks like this:
Firefox preview
In Chromium it looks like this:
Chromium preview
Ironically, when I add style="height: 100%" to the rows, the situation is reversed and in Firefox the right cell grows to the other row's height, while in Chromium its size gets minimized.
<table border="1">
<tr style="height: 100%">
<td rowspan="2">left<br><br>1</td>
<td rowspan="2">left<br><br>1</td>
</tr>
<tr style="height: 100%">
<td>right1</td>
</tr>
</table>
I want to have the default Chromium behavior (the cell on the right using the same height as the rowspan cells) in both Firefox and Chromium.
Though in my specific case, I would also accept it if I kind of get the same behavior as in Firefox in both browsers but with the cell aligned to the top rather than the bottom.
This is the problem with every web browser. Try using normalize.css.
Under the hood, normalize.css does no magic. It just overrides some of the properties that the browser has set so as to make the HTML document the same throughout various browsers.
Be careful though, if you are also including another CSS document in your HTML document, the order of the positioning matters.
Normalize.css

Why does Safari treat these table cells so differently than chrome and firefox?

Here is some very simple HTML. On Chrome (v57) and Firefox (v55) the two cells to the right are the same height, and on Safari (v11) they are not. On Safari the top cell is only as big as needed for the content, and the bottom cell gets the rest of the space.
My question is - is one of these behaviours correct and one a bug? Is there something simple I can do to get Safari to produce the same results as Chrome (like is there a browser styling difference at play here)? I've inspected it and there are no user agent stylesheet differences that I can see.
img {
max-width: 100%;
display: block;
}
.image-cell {
width: 150px;
}
<table border=1 cellspacing=0 cellpadding=0 bgcolor="#3faaed">
<tr>
<td rowspan="2" class="image-cell">
<img src="http://www.rizwanashraf.com/wp-content/uploads/2009/04/gorgeous-chrysanthemum-3d-wallpaper.jpg" />
</td>
<td>Top Cell</td>
</tr>
<tr>
<td>Bottom Cell</td>
</tr>
</table>
I know there are a limitless number of ways that I can produce a image with two equal sized boxes next to it - that isn't the question. The question is, why the difference, and, can simple styling be added to homogenize them? (This is a learning question, as I say, there are a million ways to display two boxes beside a box. That's not what I'm asking.)
The spec leaves this explicitly undefined:
CSS 2.2 does not specify how cells that span more than one row affect row height calculations except that the sum of the row heights involved must be great enough to encompass the cell spanning the rows.
This means in particular that CSS does not define how the height of a cell spanning more than one row is distributed across the rows that it spans.
There is no good way to homogenize the table's appearance except by providing absolute heights to the table and/or the table rows. Given an arbitrary image whose height is not known in advance, this is pretty much impossible with CSS table layout.
Table cells are rendered arbitrarily depending on their content, so you can never be sure how they are going to be rendered. Specifying dimensions is the way to get specific results.

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.

Chrome does not respect display property on table elements

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>

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>