Datagrid CssClass being overridden by TD style

L

Laurence Neville

Since I added a style for TD elements to my style sheet I have been unable
to control the look of datagrids using the CssClass properties. Maybe there
is no way round it, but I really need to keep the TD style in place to
control other elements on the page.

Is there a way around this?

Here is the code from my datagrid:

<ASP:DataGrid EditItemStyle-CssClass="SubNormal"
FooterStyle-CssClass="SubNormal" HeaderStyle-CssClass="SubNormal"
ItemStyle-CssClass="SubNormal" id="MyDataGrid1" runat="server"
CssClass="SubNormal" EnableViewState="True"
Width="100%" BackColor="#ffffff" BorderColor="black" ShowFooter="false"
CellPadding="3" CellSpacing="0"
HeaderStyle-BackColor="#ffcc66" DataKeyField="RowHeading_1"
AutoGenerateColumns="false" OnEditCommand="MyDataGrid1_Edit"
OnCancelCommand="MyDataGrid1_Cancel" OnUpdateCommand="MyDataGrid1_Update">

Here is the code from my CSS file:

BODY, TD, P, LI, BLOCKQUOTE {
font-family: verdana,arial,geneva,sans-serif;
font-size: 13px;
font-weight: normal;
color: #333333;
}

..SubNormal
{
font-family: verdana,arial,geneva,sans-serif;
font-size: 11px;
font-weight: normal;
color: #333333;
}

As you can see, all that I am trying to do is reduce the font in the
datagrid to 11px rather than the standard 13px
 
G

Guest

The problem is that IIRC the css class for the datagrid is applied to the
<tr> tags and not the <td>, so your first rule applies directly to the <td>
and is overriding the .SubNormal style on the <tr>. (Somebody correct me if
I'm wrong about where datagrid applies css classes.)

To fix this, you can just make your second rule more specific:
..SubNormal TD {
font-size: 11px;
}

Note also that you can take out the other style bits from this rule, since
they are identical to the first rule and will inherit.
For more information about rule specificity and the cascade, see
http://www.w3.org/TR/REC-CSS2/cascade.html#cascade

HTH
 
L

Laurence Neville

Thanks, adding TD to the .SubNormal rule did the job. I also removed the
redundant rules as you suggested.

Thanks again.

Laurence Neville
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top