CSS and ASP.NET controls
I've noticed when trying to apply the 's开发者_如何学Ctyle' attribute to an asp:TextBox control, for example or when attempting to use a css class to apply a style, it doesn't take. I have to specifically set the attribute. For instance:
<asp:TextBox runat="server" ID="DescriptionTextBox" BackColor="#F7FCFF" /> // Works
<asp:TextBox runat="server" ID="DescriptionTextBox" CssClass="textbox" /> // Doesn't work
<style type="text/css">
.textbox
{
background-color: #F7FCFF;
}
</style>
I know this is a simple question, but can someone kindly shed some light on it for me?
Thank you
Don't get too confused over what an asp control actually is. In fact all it does is generate HTML, which is what the CSS is then applied to.
Your second example with CssClass
should work, but instead of debugging by looking at your aspx you really need to check out the HTML (using your browsers version of the developer tools such as Firebug will show you what styles are being applied).
The text box control probably generates either style attribute with background colour or uses more specific CSS rule.
Check the html generated and use FireBug to see which CSS rules are applied / overridden.
Everything looks to be correct. Make sure that you are linking your style sheet between your head tags, or if you opt to go the route of inline tags, those also need to be in between the head.
<html>
<head>
<link href="StyleSheet.css" type="text/css" rel="stylesheet" />
</head>
<body>....
OR
<html>
<head>
<style type="text/css">
.textbox
{
background-color: #F7FCFF;
}
</style>
</head>....
Remember that there isn't an actual TextBox control in HTML so unless it gives you the property (like asp.net does) you must have that CssClass that you used. Also, if you are using the format in your example as is to compare that is where your problem is. See my second code block for where the style should be.
Hope that helps
Tony
You could also do something like DescriptionTextBox.style.add("background-color", "#fff") in your code behind.
精彩评论