首页 > 解决方案 > 当文本框内容可编辑为假时如何更改文本颜色?

问题描述

内容可编辑真/假时如何更改样式?当可编辑为真时需要红色,当它为假时需要灰色。这在 CSS 中可能吗?

这是我的html代码:

<body spellcheck="false" autocorrect="off" contenteditable="false" style="color:gray;>
  Need to change color of the text when it is false
</body>

标签: jqueryhtmlcssbootstrap-4contenteditable

解决方案


使用 css选择器,attribute
这里是关于 css 中选择器的教程:https ://www.w3schools.com/cssref/css_selectors.asp

body[contenteditable="true"]{
    color:red;
}
body[contenteditable="false"]{
    color:grey;
}

推荐阅读