Forum Moderators: not2easy

Message Too Old, No Replies

Inherting from table cells to form elements

Why doesnt it work?

         

aspdaddy

11:24 am on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought that a class like:

.bgfdfcfd
{
background-color:#fdfcfd;
}

Could be used like this and would inherit to the checkboxes unless the checkbox overides it.


<td class=bgfdfcfd>
R&nbsp;<input type=checkbox name="R">&nbsp;
U&nbsp;<input type=checkbox name="U">&nbsp;
F&nbsp;<input type=checkbox name="F">&nbsp;
W&nbsp;<input type=checkbox name="W">&nbsp;
C&nbsp;<input type=checkbox name="C">&nbsp;
</td>

But you have to do it like this (which is a maintenance nightmare!)


<td>
R&nbsp;<input class=bgfdfcfd type=checkbox name="R">&nbsp;
U&nbsp;<input class=bgfdfcfd type=checkbox name="U">&nbsp;
F&nbsp;<input class=bgfdfcfd type=checkbox name="F">&nbsp;
W&nbsp;<input class=bgfdfcfd type=checkbox name="W">&nbsp;
C&nbsp;<input class=bgfdfcfd type=checkbox name="C">&nbsp;
</td>

Is there a workaround? Thanks

Span

11:47 am on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Background" doesn't inherit. You could use a descendant selector:

.bgfdfcfd input {
background-color:#fdfcfd;
}

But that will affect all input elements in .bgfdfcfd

Also possible, the attribute selector, this will set a background for checkboxes only, but is not supported by IE:


.bgfdfcfd input[type="checkbox"] {
background-color:#fdfcfd;
}

Note that not all browsers support the styling of form elements.