MVC 4 Webgrid - Column width options using css style not working

I am trying to set the width for a Webgrid column. But that does not work. Someone help me.

Please find below my code

@grid.GetHtml(
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
alternatingRowStyle: "webgrid-alternating-row",
mode: WebGridPagerModes.All,
columns:grid.Columns(
grid.Column(columnName:"ID", header: "ID",canSort:true, style: "id"),
grid.Column(columnName:"Name", header: "Name",canSort:true,style: "name")
)

And my css file

.webgrid-table { border: 1px solid #98BF21;   }
.webgrid-header { background-color: #A7C942; color: #FFFFFF; text-align: left;}
.webgrid-alternating-row { background-color: #EAF2D3; }
.id { width: 20px; }
.name { width: 40px; }

Anyone help me?

+4
source share
1 answer

To solve this problem, you need to specify the width of the itself WebGrid.

Add this

.webgrid-table { *width*: *specify the width value here* ;border: 1px solid #98BF21;}
+3
source

Source: https://habr.com/ru/post/1547883/


All Articles