Search code examples
cssasp.net-mvc-3webgrid

MVC Webgrid, is it possible to add css style to a single columns header?


I am using MVC4 and the WebGrid control.

I need to apply CSS styles to all the columns headers except for the first column

Currently my code is:

@{
   Webgrid grid = new WebGrid(Model.entrySheet.data);
   grid.GetHtml(columns:Model.columns,headerStyle:"webgridHeader");
 }

This applies the css style "webgridHeader" to all columns.

Is there anyway to style the indvidual style of each header column header?

I would perfer a non-javascript solution.


Solution

  • Don't know how dynamic it should be. But if the amount of columns is fixed, you may get what you want by using :nth-child(x) in css. Of course, older browser don't understand that.

    Or, if it is just the first column, you can use the pseduo class :first-child which is known by many more browsers, even IE7 as far as I know.