tags:

views:

558

answers:

2

A GWT tree looks roughly like this:

<div class="gwt-Tree">
    <div style="padding-top: 3px; padding-right: 3px;
                padding-bottom: 3px; margin-left: 0px;
                padding-left: 23px;">
         <div style="display:inline;" class="gwt-TreeItem">
              <table>
                   ...
              </table>
         </div>
    </div>
    <div ...>
    </div>
    ...
</div> 

My question is: how should I change the padding of the individual tree rows? I suppose I could do something along the lines of setting CSS rules for .gwt-Tree > div but that seems hacky. Is there a more elegant way?


Resolution: Apparently there is NOT a more elegant way. Here is what we did, FWIW:

 .gwt-Tree > div:first-child { 
      width: 0px !important; 
      height: 0px !important; 
      margin: 0px !important; 
      padding: 0px !important; 
 } 

 .gwt-Tree > div {
      padding: 0px 5px !important;
 }

 .gwt-Tree > div[hidefocus=true] {
      width: 0px !important;
      height: 0px !important;

      margin: 0px !important;
      padding: 0px !important;
 }
+1  A: 

You could do it like this:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
    <title>Test</title>
    <style type="text/css">
    .gwt-Tree {background:green;}
    .gwt-Tree div {padding-top: 3px; padding-right: 3px;padding-bottom: 3px; margin-left: 0px;padding-left: 23px;background:gray;}
    .gwt-Tree div .gwt-TreeItem {padding:0;margin:0;background:red;color:#fff;}
    </style> 
</head>
<body>
<div class="gwt-Tree">
    <div>
         <div class="gwt-TreeItem">
            random
         </div>
    </div>
    <div>
         <div class="gwt-TreeItem">
            random
         </div>
    </div>
</div> 
</body>
</html>

Note that .gwt-Tree div will affect all child divs, so you have to reset them back to the style you want with .gwt-Tree div .gwtTreeItem.

About the "hacky >" you said - > selector is supported in all browsers except for IE6 who won't recognize it.

easwee
sorry i don't think that's what i'm looking for: that allows me to customize the CSS of the first or third level div, but not the second-level div, the one with the padding...
Epaga
Aha sorry - i missunderstood your question - edited answer.
easwee
A: 

I took a look at the GWT Tree Documentation. The CSS style rules for the tree and tree items are

CSS Style Rules

.gwt-Tree
the tree itself

.gwt-Tree .gwt-TreeItem
a tree item

.gwt-Tree .gwt-TreeItem-selected
a selected tree item

You probably want to add the padding to .gwt-Tree .gwt-TreeItem and to .gwt-Tree .gwt-TreeItem-selected

Carnell
The question was not about the TreeItem div, but the div between the Tree and the TreeItem.
gamma
@gamma ... The page i reference to lists the TreeItem and Tree. So the div/css name for the TreeItem is listed there. Its also listed in the text of my answer. Read the entire doc before down voting.
Carnell
@Carnell unfortunately Gamma is right though: if you see my question, you'll see three levels: the tree (gwt-tree), the second level with the padding that I want to change, and the treeitem (gwt-treeitem). And the question is about styling the div which CONTAINS the treeitem.
Epaga
@Epaga Check my edited question.
easwee
You really shouldn't be doing anything with the div in between the gwt-Tree and the gwt-TreeItem. This is just an extra div that could eaisly go away in future GWT releases. Also from your example it looks like there is always only one get-TreeItem div contained within this middle div. If this is the case using either this middle div or the get-TreeItem would have similar behavior.
Carnell
@Carnell The problem is that setting padding on gwt-TreeItem does not change the padding of the tree items! The padding is still defined by the surrounding div.
Epaga
@Epaga If that is the case it sounds like there is a GWT bug. You should open one up at http://code.google.com/p/google-web-toolkit/issues/list
Carnell