tags:

views:

28

answers:

1

Let's say i have the following ASP.NET/CSS code:

<div style="color:Red;"> some text...<asp:Button runat="server" ID = "Button1" Text = "ABC" /> </div>

The "some text" part would be red but the text of the button is not red. Why? If I place a label in place of the button, the label's text would be red.

A: 

I suggest you use Firebug for Firefox to inspect the rendered html and the CSS styles that are acting on it.

An <asp:Button /> control does not render to a label, it renders to a HTML <input /> tag.

Your default styles for a <label /> and a <input /> could be completed different. A quick fix would be:

<style type="text/css">.red { color:Red!important; }</style>

<asp:button id="myButton" class="red" runat="server">My Button Text</asp:button>
Markive
Hi what I mean is when you put a Button inside a <div> element, the Botton control is not influenced by the css styles of the <div> element, which is puzzling.
Aperture
It all boils down to CSS Specificity in the end.. Your button WILL inherit the 'color' style so long as there isn't another more specific style that overwrites it.. The easiest way to find out is to download jBug for Firefox, right click on your button in Firefox and chose 'Inspect Element' then in the right panel see what CSS styles are being applied to it, you can also change the styles in real time to see what you need to change.. It is an invaluable tool (for JS too!) Good luck!
Markive