c# - 从后面的代码添加多个内联样式

标签 c# asp.net

我知道我可以通过这种方式从代码中添加样式

imgStory1.Style.Add("display","block");
imgStory1.Style.Add("border", "none"); 
imgStory1.Style.Add("outline", "none");
imgStory1.Style.Add("height", "auto !important");

等等,但如果可能的话,我想以一种更有效的方式来做。请注意,我无法通过 CSS 执行此操作,它必须是内联样式。

最佳答案

这里有一种写在一行中的方法

imgStory1.Attributes.Add("style", "display: center;border: none; outline: none");

用于覆盖现有的

imgStory1.Attributes["style"] = "display: center;border: none; outline: none";

关于c# - 从后面的代码添加多个内联样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39462929/

相关文章:

c# - 使用 List(T).GroupBy() 对嵌套对象进行分组

C# 鼠标右键单击和控制焦点

c# - 无法在 gridview 中访问 TextArea 中的文本

css - 如何将 INSPINIA Bootstrap 添加到 Ember 应用程序

c# - 尝试使用 C#.Net 编码 HMAC-SHA256

c# - 如何验证远程 ssl 证书?

c# - 结合两个列表和 linq 查询以按不同列表中的两个不同字段排序

asp.net - ASP.NET 或 HTML 页面中的 PDFTron Web 查看器 - 加载 pdf 或 xod 显示错误

c# - 无法获取GridView中Linkbutton的文本

asp.net - 从文本框中获取印地语字符的输入并将其存储到数据库