【发布时间】:2020-09-17 11:37:23
【问题描述】:
我有一个要求在我的项目中给出特定类型的样式,默认情况下。选择标记的占位符值在选择“禁用”时。 我知道可以使用 select:invalid 给出它,但我发现它仅在 select 是“必需”时才有效,但我想要以下场景的解决方案。
<select disabled>
<option disabled value="" selected>- please choose -</option>
<option value="1">Apple</option>
<option value="2">Banana</option>
</select>
注意: 我必须解决的要求是在选择框中的占位符选项,即禁用的选项“-请选择-”必须是斜体,其余选项必须是正常字体样式。即使选择框被展开。 so you see in the "required state" I am able to give them different styles using :invalid selector(which doesn't works when the select is in "disabled state"), but in the disabled state, I am able to give just一种类型,即斜体或正常,如果选择了一个选项并且选择框在某些条件下被禁用/不可编辑,则由于斜体样式,该选项看起来像是一个占位符。
【问题讨论】:
-
这能回答你的问题吗? How to style Disabled Options in a form