我想在網格中顯示縮略圖圖像。Vaadin 8.2.0:如何垂直對齊網格單元格中的圖像
這是我的相關代碼(簡化):
addColumnVisibilityChangeListener(event -> {
if (ID_THUMBNAIL.equals(event.getColumn().getId())) {
if (event.isHidden()) {
setBodyRowHeight(-1);
} else {
setBodyRowHeight(130);
}
// needed to force rendering of current values
getDataProvider().refreshAll();
}
});
// rescale returns a (cached) ExternalResource, image is 120x120px max
// aspect ratio is preserved, so at least width or height is 120px
grid.addColumn(this::rescale, new ImageRenderer<>(this::showImage))
.setCaption(ID_THUMBNAIL)
.setStyleGenerator(r -> ID_THUMBNAIL)
.setWidth(131);
的CSS是:
.asset-grid td.thumbnail {
// height is set bij Vaadin Grid
padding: 5px;
text-align: center !important;
}
.asset-grid td.thumbnail img {
vertical-align: middle !important;
}
一切正常,除了縮略圖的垂直對齊方式。它顯示在單元格的頂部。我嘗試了幾個設置,但沒有任何工作。
你有沒有嘗試廣告d:「display:table-cell; 「to .asset-grid td.thumbnail? – 1011sophie
剛剛嘗試過,沒有什麼區別 – rmuller
我有一些工作解決方法,但是它取決於你如何設置行高,所以如果你可以提供[sscce] (http://sscce.org),所以我們可以考慮所有的元素 – Morfic