C# 为 ASP.NET 中的 <UL> 和 <LI> 等 HTML 通用控件应用 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1763211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 20:36:06  来源:igfitidea点击:

Apply CSS for an HTML generic control like <UL> and <LI> in ASP.NET

c#.netasp.nethtmlcss

提问by ACP

I don't know how to apply CSS for a HTML generic control like <UL>and <LI>given runat="server"in ASP.NET. I am finding the <li>in a master page from a content page. Once I found that control I want to apply CSS.

我不知道怎么样为一个HTML通用控制应用CSS<UL><LI>给出 runat="server"在ASP.NET。我正在<li>从内容页面的母版页中找到。找到该控件后,我想应用 CSS。

<ul id="mainMenu" runat="server" style="width:350px;">
    <li id="mainHome" runat="server"><a title="Home" href="#" class="home">Home</a></li>

    <li id="mainManage" runat="server"><a title="Manage" href="#"
                                          class="manage">Manage</a></li>

    <li id="mainEnquiry" runat="server"><a title="Enquiry" href="#"
                                           class="enquiry">Enquiry</a></li>

    <li id="mainReport" runat="server"><a title="Report" href="#"
                                          class="report">Reports</a></li>
</ul>

采纳答案by Muhammad Akhtar

Please try this,

请试试这个,

ull.Style.Add("background-color", "Red");

Or, I have tested this, will definitely work, please check

或者,我已经测试过了,肯定会工作,请检查

ull.Attributes.Add("class", "yourClass");

Edit:To test this solution I have provided you:

编辑:为了测试这个解决方案,我为您提供了:

  1. make new blank master page and put <ul runat="server" id="ull">

  2. then add a new page and use the above master page.

  3. make findcontrol ul and put in CSS as I have mentioned in the answer.

  4. then run your page, and view source of your HTML page and you will find what you are looking for. Like

  1. 制作新的空白母版页并放置 <ul runat="server" id="ull">

  2. 然后添加一个新页面并使用上面的母版页。

  3. 正如我在答案中提到的那样,制作 findcontrol ul 并放入 CSS。

  4. 然后运行你的页面,查看你的 HTML 页面的源代码,你会找到你要找的东西。喜欢