views:

44

answers:

1

I've got a multi-column panelGrid setup, with dataTables as each of the columns. Each of the dataTables is a different length. This results in the panelGrid stretching out to fit the largest dataTable (so far, that's good). The remaining dataTables are centered vertically (this is not good as it looks horrible on screen) instead of being top justified.

How can I tell panelGrid to top-justify contents? Or, is my approach completely wrong and I need to do something different (if so, suggestions are welcome)?

+2  A: 

JSF just renders basic HTML. Styling is to be done with CSS. Rightclick the page in your webbrowser and choose View Source. You'll see that the <h:panelGrid> renders a HTML <table> element and that those <h:dataTable> are been rendered as a HTML <table> element as well which in turn are nested inside the <td> element rendered by the <h:panelGrid>. So, you basically just want to set the vertical-align of the <td> of the <h:panelGrid> to top.

Assuming that the <h:panelGrid> has an id which ends up as <table id="panelGridId"> in HTML, use the following CSS:

#panelGridId>tbody>tr>td { 
    vertical-align: top;
}

See also:


Update: It should work. Here's a copy'n'paste'n'runnable example.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>SO question 3547485</title>
        <style>#myid>tbody>tr>td { vertical-align: top; }</style>
    </head>
    <body>
        <table id="myid">
            <tbody>
                <tr>
                    <td><table><tbody><tr><td>n1a</td></tr><tr><td>n1b</td></tr></tbody></table></td>
                    <td><table><tbody><tr><td>n2a</td></tr></tbody></table></td>
                    <td><table><tbody><tr><td>n3a</td></tr><tr><td>n3a</td></tr><tr><td>n3c</td></tr></tbody></table></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

All get aligned to top. Without the rule, all get centered. It's hard to tell what rule exacty you need to apply since it's unclear how your generated markup look like.

BalusC
Ugh. I'm sure you're right, but a couple hours of fiddling with it and I still can't get it to do anything different. Just wanted to let you know that I'll accept the answer as soon as I can make it work!
Brian Knoblauch
Sorry, I forgot to put a `tr` in between. You could alternatively also set `td { vertical-align: top; }` but this will be applied on **all** `td` elements the document is aware of. Not sure if this is what you want.
BalusC
Well, I still can't get it to work. I've tried every combination I can think of (in our CSS file for this project) and it's just ignored. Is there a way to inject it directly instead of placing it in our master CSS?
Brian Knoblauch
See the update.
BalusC
OK, got it working. I ended up sticking the <style> element directly into the head section of my xhtml file and using the alignment for all td elements. Unable to get it to work at all if in our CSS file (despite other things coming through fine, such as colors). Also, unable to restrict it to just the particular td elements that needed it. Fortunately in this case it's safe to apply to all td on the page. Thank you very much for your help! This has been an extremely frustrating problem!
Brian Knoblauch
You're welcome.
BalusC