asp.net - 用户控件样式

标签 asp.net css user-controls

我有一个包含这段代码的 .ascx 页面:

<%=Morning%>
  <br />
<%=Sunrise%>
  <br />
<%=afternoon%>

在.ascx.cs 后面的代码中

XmlNodeList _morning= _doc.GetElementsByTagName("morning");
  morning= "morning" + _morning[0].InnerText.ToString();

XmlNodeList _sunrise = _doc.GetElementsByTagName("sunrise");
  Sunrise = "Sunrise" + _sunrise[0].InnerText.ToString();

所以结果看起来像:

morning  12:00 PM
Sunrise  5:00 AM

我想做的是在每个元素上添加样式;我需要 morning 使用一种样式,12:00 PM 使用另一种样式。我如何使用 CSS 做到这一点?我的意思是,我如何指定每个人都有自己的类(class)?

最佳答案

morning = "<span style='color: Red;'>morning</span><span style='color: Yellow;'>" + _morning[0].InnerText.ToString() + "</span>";

这将改变 morning 的颜色到红色和time的颜色到黄色。但是,这是内联样式,您可以改用类。

morning = "<span class='morning'>morning</span><span class='time'>" + _morning[0].InnerText.ToString() + "</span">";

在你的 CSS 文件中:

.morning
{
    color: Red;
}

.time
{
    color: Yellow;
}

关于asp.net - 用户控件样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6611364/

相关文章:

javascript - 单击内部 anchor 时如何防止切换效果?

css - Firefox 的水平导航位置问题

ASP.NET 确定在页面加载事件中的 updatepanel 内单击了哪个按钮

c# - "The Controls collection cannot be modified because the control contains code blocks"

asp.net - 将 NuGet 与 ASP.NET "Web Site"项目中的 *.dll.refresh 文件与 Web 部署项目一起使用

asp.net - 母版页没有 LoadComplete?

php - 在 php 中使用 css 伪元素不起作用

c# - 如何从用户控件中的主窗体读取属性

c# - 从数据库中保存/检索/比较 CheckboxList 值

负载均衡环境下的Asp.net session 管理