CSS 和 ASP.NET 控件
我注意到,当尝试将“style”属性应用于 asp:TextBox 控件时,例如,或者当尝试使用 css 类来应用样式时,它不需要。我必须专门设置该属性。例如:
<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've noticed when trying to apply the 'style' 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要对 ASP 控件的实际含义感到太困惑。事实上,它所做的只是生成 HTML,然后应用 CSS。
您使用
CssClass
的第二个示例应该可以工作,但是您实际上需要检查 HTML(使用浏览器版本的开发人员工具,例如Firebug 将向您显示正在应用的样式)。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).文本框控件可能会生成具有背景颜色的样式属性或使用更具体的 CSS 规则。
检查生成的 html 并使用 FireBug 查看应用/覆盖了哪些 CSS 规则。
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.
一切看起来都是正确的。确保您在 head 标签之间链接样式表,或者如果您选择使用内联标签,这些标签也需要位于 head 之间。
或者
请记住,HTML 中没有实际的 TextBox 控件,因此除非它为您提供属性(如 asp.net 那样),否则您必须拥有您使用的 CssClass。另外,如果您按原样使用示例中的格式进行比较,那就是您的问题所在。请参阅我的第二个代码块以了解样式应该在哪里。
希望对
托尼有帮助
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.
OR
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
您还可以在后面的代码中执行类似 DescriptionTextBox.style.add("background-color", "#fff") 的操作。
You could also do something like DescriptionTextBox.style.add("background-color", "#fff") in your code behind.