leora leora - 1 year ago 60
ASP.NET (C#) Question

Skip css formatting on one html table

I have CSS items for all my table elements (

, etc...) but I have one table for which I don't want the CSS to apply.

What is the quickest way to have this table just display as a raw HTML table and not apply my CSS formatting.

Also, in my CSS file, I have this:

table td
padding: 5px;
border: solid 1px #e8eef4;

table th
padding: 6px 5px;
text-align: left;
background-color: #FFFFFF;
border: solid 1px #e8eef4;

what if I want to have multiple table formats, how do I do this?

Answer Source

You should use classes to define several different styles, e.g:

// global table styles - will be applied to all tables
table td
  background-color: green;

// styles for tables with class "style1"
table.style1 td
  border: solid 1px red;
table.style1 th

// styles for tables with class "style2"
table.style2 td
  border: solid 1px blue;
  background-color: white;

Then set the class attribute on the tables where you want to apply that style:

<table class="style1"><tr><td> red border, green background </td></tr></table>

<table class="style2"><tr><td> blue border, white background </td></tr></table>

<table><tr><td> default border, green background </table>

Here style1 is applied to TDs of the first table, style2 to TDs of the second table.

Note that global styles (without any class name) apply to all matching elements (e.g. TDs), but these styles can be overridden by specific styles (as shown with the background-color, which is globally set to green, but overridden for style2).

BTW: for a tutorial about CSS, have a look at http://w3schools.com/css/.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download