我按如下方式定义一个列:
{
name: 'button',
displayName: '',
cellClass: 'ui-grid-vcenter',
enableColumnMenu: false,
enableFiltering: false,
enableSorting: false,
cellTemplate: '<div><button ng-click="grid.appScope.rowButtonHandler(row.entity.id)">clicky</button></div>'
}结果是:
<div class="ui-grid-cell ng-scope ui-grid-coluiGrid-010 ui-grid-vcenter" ui-grid-cell="" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name">
<div class="ng-scope">
<button ng-click="grid.appScope.rowButtonHandler(row.entity.id)"></button>
</div>
</div>我想让这个按钮在垂直和水平方向居中。在水平方向上,可以工作,但在垂直方向上,我似乎不能正确使用CSS。这是我的通用解决方案:
.ui-grid-vcenter div {
text-align: center;
vertical-align: middle !important;
background-color: yellow !important;
}在这种AngularJS网格中,如何将单元格中的内容居中?
发布于 2015-06-03 07:05:43
使用相对位置:
.ui-grid-vcenter div {
background-color: yellow !important;
text-align:center;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}发布于 2015-12-19 03:18:33
使用css flex会让它变得更容易(https://css-tricks.com/snippets/css/a-guide-to-flexbox/):
假设这是您的cellTemplate (myCellTemplateForEditAndDelBtns.html):
<div id="editBtns" class="flexParent">
<span class="flexChildren">
<button><i class="fa fa-pencil-square-o "></i></button>
<button><i class="fa fa-times gridDelBtn"></i></button>
</span>
</div>您可以在columDefs中将其添加到您的单元格中:
$scope.myGrid.columnDefs = [
...
{ name: 'edit',
enableCellEdit: false,
enableFiltering: false,
enableSorting: false,
cellTemplate: 'location-to/myCellTemplateForEditAndDelBtns.html',
width: '5%'
}
];最后使用了CSS Flex
#editBtns {
height: 100%;
}
.flexParent {
display: flex;
justify-content: center;
}
.flexChildren {
align-self: center;
}https://stackoverflow.com/questions/30607173
复制相似问题