I have a MVC5 application which uses bootstrap. The table column name is in black on white background and I want to change it to a blue background and the column name will be in white, how could I do that? I tried to play with the CSS classes without success...
<input type="button" value="Add" onclick="addRow()" class="data-button" id="add-row" />
<table class="table" >
<tr>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th>
@Html.DisplayNameFor(model => model.checkBox1)
</th>
<th></th>
</tr>
To change a background-color of <thead> (or any other element) use our color classes. If you are going to use a dark background you should also consider white text (to provide a proper contrast) by adding the . text-white class.
By default the header of a Tabular report is white. In order to customize the Table header color, you can do it by adding either CSS or Javascript Code. Also, you can use color name or its hex code and can customize the table header color accordingly.
In your CSS
th {
background-color: blue;
color: white;
}
You could simply apply one of the bootstrap contextual background colors to the header row. In this case (blue background, white text): primary.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<table class="table" >
<tr class="bg-primary">
<th>
Firstname
</th>
<th>
Surname
</th>
<th></th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Roe</td>
</tr>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With