代码之家  ›  专栏  ›  技术社区  ›  Epaga Alex Reynolds

吕震中本:你们要改变树木的行距吗?

  •  5
  • Epaga Alex Reynolds  · 技术社区  · 15 年前

    <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> 
    

    我的问题是:我应该如何更改单个树行的填充?我想我可以做一些类似于设置CSS规则的事情 .gwt-Tree > div


     .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;
     }
    
    3 回复  |  直到 15 年前
        1
  •  2
  •   easwee    15 年前

    你可以这样做:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <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>
    

        2
  •  3
  •   chux    13 年前

    我也遇到了同样的问题,并试图用CSS来解决它,但没有运气。 最后,我成功地更改了java代码中的顶部和底部填充:

    /**
        * handle top and bottom padding issue of leafs the grandparent DOM element (div) has disturbing top and bottom
        * padding of 3px, which is changed here to 0px
        * 
        * @param uiObject
        *           uiObject which is a leaf in the tree
        */
       private static void correctStyle(final UIObject uiObject) {
          if (uiObject instanceof TreeItem) {
             if (uiObject != null && uiObject.getElement() != null) {
                Element element = uiObject.getElement();
                element.getStyle().setPaddingBottom(0, Unit.PX);
                element.getStyle().setPaddingTop(0, Unit.PX);
             }
          } else {
             if (uiObject != null && uiObject.getElement() != null && uiObject.getElement().getParentElement() != null
                   && uiObject.getElement().getParentElement().getParentElement() != null
                   && uiObject.getElement().getParentElement().getParentElement().getStyle() != null) {
                Element element = uiObject.getElement().getParentElement().getParentElement();
                element.getStyle().setPaddingBottom(0, Unit.PX);
                element.getStyle().setPaddingTop(0, Unit.PX);
             }
          }
       }
    

    Anchor fileDownloadLink = new Anchor();
    fileDownloadLink.setStyleName(ViewConstants.STYLE_LINK_FILE_DOWNLOAD);
    fileDownloadLink.setText(subSubStructure.getName());
    fileDownloadLink.setHref(ViewConstants.HREF_DOWNLOAD_FILE_EXTRACTED_DATA + subSubStructure.getPath());
    treeItem.addItem(fileDownloadLink);
    StyleCorrector.correctStyle(fileDownloadLink);
    
        3
  •  0
  •   Carnell    15 年前

    我看了一下GWT Tree Documentation

    CSS样式规则

    .gwt树
    树本身

    .gwt树.gwt树
    树项目


    选定的树项目

    你可能想把填充物加到 .gwt树.gwt树 已选择.gwt树.gwt树项目