gpt4 book ai didi

c# - 从后面的代码添加 div 元素的宽度

转载 作者:行者123 更新时间:2023-11-30 13:52:02 25 4
gpt4 key购买 nike

在 aspx 页面中,我有带有 id="progressBar"runat="server" 的 div。我需要从 C# 中的代码后面添加 div 的宽度.

谁能帮我解决这个问题?

最佳答案

你可以设置它为Style property ,像这样:

progressBar.Style[HtmlTextWriterStyle.Width] = "200px";
//or just use a string:
progressBar.Style["width"] = "200px";

或者,您可以给它一个 CSS 类,在您的 CSS 中定义它:

.progress { width: 200px; }

然后像这样在您的标记中分配该类:

<div id="progressBar" runat="server" class="progress">

或者在你的代码隐藏中:

progressBar.Attributes["class"] = "progress";

关于c# - 从后面的代码添加 div 元素的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3361429/

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