views:

900

answers:

2

I'm struggling to apply css-styling to a GWT (Google Web Toolkit) generated html table in Safari. Specifically, I cannot get Safari to respect the height attribute of a table row after I trigger any kind of re-draw of the table.

The following basic example illustrates the problem:

<html>
    <head>
     <style type="text/css">
      tr {
       height: 50px;
       font-weight: bold; /* added to prove that other style rules are re-applied when enabling css again */
      } 
     </style>
    </head>
    <body>
     <table border="1px">
      <tr>
       <td>one</td>
       <td>two</td>
       <td>three</td>
      </tr>
     </table>
    </body>
</html>

If I open this page in Safari it renders correctly at first. If I then choose "disable styles" from the Develop menu and then immediately re-enable them again, the heigh rule is ignored and the height of the table row is calculated as if it were set to "auto".

This is exactly what happens when rows/cells are added or removed programatically in my GWT FlexTable.

Does anyone know what causes this behavior and if there is a workaround that does not require setting a fixed height on the entire table?

Details: Running Safari Version 4.0.3 (5531.9) on Mac OSX Leopard
The problem also occurs using the GWT Hosted Mode browser (which essentially is Safari when running it on a mac)

Thanks, Joakim

+2  A: 

TR tags have no height attribute in the W3C specs. You should set the height of the TD tags it contains, instead.

ceejayoz
Are you sure about that? I was under the impressions that it was the "tag" height attribute that was deprecated but that setting height as a css style rule was ok. That is: Not ok: <tr height="XX"> Ok: <tr style="height: XX;">The second paragraph under 17.5.3 on http://www.w3.org/TR/CSS2/tables.html#height-layout says: The height of a 'table-row' element's box is calculated once the user agent has all the cells in the row available: it is the maximum of the row's specified 'height' and the minimum height (MIN) required by the cells.
sarnelid
Hmm. W3Schools lists no height attribute for `TR`s in any DTD (http://www.w3schools.com/tags/tag_tr.asp) but lists it under `TD` (http://www.w3schools.com/tags/tag_td.asp) as deprecated to CSS.
ceejayoz
Exactly, but it does have a style attribute, and I'm trying to apply the height setting as a style rule, not as a direct "tag" attribute.
sarnelid
@sarnelid, it doesn't matter *how* you're applying the 'height' (whether via the `style: XX` or `height="xx"`), the problem is that the table-row's height is determined by the height of the table-cells. This makes sense, if you think of the `<tr>` as being a semantic grouping of `<td>`s, rather than an element itself (this is disingenuous, but it's how I think of it, in order to make sense of it).
David Thomas
Thanks! I guess I missinterpreted the specs. I'll stick to styling the cells from now on. =)
sarnelid
A: 

WebKit is optimized for performance and refuses sometimes to redraw certain areas, if it thinks it doesn't have to. You might be able to work around this by triggering a total redraw e.g. resizing the window by 1px and 1px back (there must be some smarter way).

stefanw
Thanks, I'll try something along those lines while still hoping for a cleaner solution.
sarnelid