我的元素中有一个名为 StyleSheet.css 的文件。
在这里,我的网络表单上的每个元素都有类。
例如:
.selectEnvironment
{
background-color: #FF0000;
}
然后我转到我的 Web 表单(一个下拉列表)上的控件,并将 CSS 类添加到它:
<div>
<asp:DropDownList ID="ddlEnvironment" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddlEnvironment_SelectedIndexChanged" CssClass="selectEnvironment">
<asp:ListItem>Select Environment</asp:ListItem>
<asp:ListItem>Development</asp:ListItem>
<asp:ListItem>Staging</asp:ListItem>
<asp:ListItem>Production</asp:ListItem>
</asp:DropDownList>
</div>
这是行不通的。这个的背景颜色没有变成红色。
我做错了什么?我对前端 Web 开发完全陌生。
最佳答案
你必须注册你的风格
<head runat="server">
<style type="text/css">
...
</style>
</head>
你也可以用这条线
<link href="MyStyles.css" rel="stylesheet" type="text/css" />
你也可以在你的代码后面注册
protected override void OnInit( EventArgs e )
{
this.Header.InnerHtml += "<link type=\"text/css\" rel=\"Stylesheet\" href=\"styleSheet.css\" />";
base.OnInit(e);
}
关于c# - 如何在 ASP .NET 中的 Web 窗体控件中实现 CSS 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12569892/