gpt4 book ai didi

asp.net - 用户控件样式

转载 作者:太空宇宙 更新时间:2023-11-04 05:20:52 28 4
gpt4 key购买 nike

我有一个包含这段代码的 .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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com