gpt4 book ai didi

c# - 如何在C#中更改元素类的属性

转载 作者:行者123 更新时间:2023-11-30 17:46:03 26 4
gpt4 key购买 nike

我有这门课

.progress {

width:200px;
height:50px;
border:1px solid black;
position:relative;
}
.progress:after {

position:absolute;
background:black;
top:0; bottom:0;
left:0;
width:10%;
-webkit-animation: filler 2s ease-in-out;
-moz-animation: filler 2s ease-in-out;
animation: filler 2s ease-in-out;
}

并有这个div

<div id="percentDIV" class="progress" runat="server">some text</div>

我想在 c# 中动态更改 progress:after class 的宽度属性。可能吗?

像什么?

percentDIV.Attributes["class:progress:after"] = "width:25%";

最佳答案

将您的下一个 div 声明为 runat="server" 并更改其样式

  percentDiv.Attributes["style"] = "width:20%";

样式优先于类。

另一种方法是从 CSS 中删除类声明,并使用 runat="server" 控件在页面标题部分动态创建它,用动态创建的 css 类替换其内容。

关于c# - 如何在C#中更改元素类的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26785986/

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