GWT 树大致如下所示:
<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>
我的问题是:我应该如何更改单个树行的填充?我想我可以按照为 .gwt-Tree > div
设置 CSS 规则做一些事情,但这似乎很老套。有没有更优雅的方式?
解决方案:显然没有更优雅的方法。这是我们所做的,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;
}
最佳答案
我遇到了同样的问题,也尝试过用 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);
关于java - GWT:更改树行的填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2492431/