简体   繁体   English

ListItem文本颜色不变

[英]ListItem Text color not changing

Hello again everyone, 大家好,

I am putting validation on a Web Form I'm making, and I set all the placeholder text to red to indicate which fields were required. 我将验证放在正在制作的Web窗体上,并将所有占位符文本设置为红色,以指示需要哪些字段。 I also have a dropdownlist that is required, so I wanted to change the text color of the first "default" option to be red also. 我也有一个必需的下拉列表,因此我想将第一个“默认”选项的文本颜色也更改为红色。 All the solutions I find across the internet say to just style it: 我在互联网上找到的所有解决方案都说只需对其进行样式设置:

<asp:ListItem style="color:red" Value=null>--Select Tax Status--</asp:ListItem>

However, this is not making any difference in Chrome or IE. 但是,这在Chrome或IE中没有任何区别。 I inspected the element and it even has the element.style color as red, but it is clearly not... 我检查了元素,它甚至具有element.style颜色为红色,但显然不是...

Anyone know how to do this so it works? 有人知道该怎么做才能起作用吗? or where I'm messing up? 还是我搞砸了?

Dropdown/ListItem render as HTML SELECT/OPTION elements - there're very limited styling you can apply to those - ie you can change background color. Dropdown / ListItem呈现为HTML SELECT / OPTION元素-您可以将样式应用于这些元素的样式非常有限-即,您可以更改背景颜色。

Your solution is either use different elements or apply a 3rd party library (eg https://select2.github.io/ ) that turns normal select into styleable elements 您的解决方案是使用不同的元素,或应用第3方库(例如https://select2.github.io/ )将常规选择转换为可样式化的元素

IMHO if you want to indicate that some fields are required you should use something like put an asterisk(*) to indicate that, and then focus and color with red (or another color) the controls they are missing when clicking the submit button, this way is more standardized and thus the users can understand easily what you are trying to tell them, because they are more familiar in this way, I think it could give a better experience to your users . 恕我直言,如果您想指示某些字段是必填字段,则应使用类似的操作将星号(*)放在上面,然后用红色(或另一种颜色)进行聚焦和着色(单击提交按钮时缺少的控件),方式更加标准化,因此用户可以轻松理解您要告诉他们的内容,因为他们对这种方式更加熟悉,我认为它可以为您的用户提供更好的体验。

However, as @Yuriy commented, the DropDownList/ListItem control is rendered into SELECT/OPTION tags, so if you set the style="color:red" to a ListItem tag only the Option tag is going to be red. 但是,正如@Yuriy所评论的那样, DropDownList/ListItem控件呈现到SELECT/OPTION标记中,因此,如果将style="color:red"设置为ListItem标记,则只有Option标记将变为红色。

You should apply the style to the DropDownList control as below: 您应该将样式应用于DropDownList控件,如下所示:

<asp:DropDownList ID="ddl" style="color: red;" runat="server">
    <asp:ListItem>--Select Tax Status--</asp:ListItem>
</asp:DropDownList>

It will be rendered as 它将呈现为

<select name="ddl" id="ddl" style="color: red;">
    <option>--Select Tax Status--</option>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM