例如用伪类:focus可以区分获取焦点与无焦点的元素,并且是动态的 我想在页面input没有输入东西时一种表现,当用户一输入时又一种表现,动态的,能用选择器区分开来吗?
认证0级讲师
There seems to be no input, but the placeholder can be partially customized, such as setting a background color, etc. This also achieves the purpose of distinguishing whether there is content using pure CSS.
::-webkit-input-placeholder { color: #000; background: red; border: 1px solid #000; }
However, you can also consider using <p contenteditable></p> and p:empty to implement the text box and its status with or without input.
<p contenteditable></p>
p:empty
<style> p:empty { color: #999; } p:empty::before { content: "Empty"; } </style> <p contenteditable></p>
No, it is more appropriate to use JS to achieve this effect.
It doesn’t seem to exist at the moment, but if it does, it will definitely be more convenient than JS
There seems to be no input, but the placeholder can be partially customized, such as setting a background color, etc. This also achieves the purpose of distinguishing whether there is content using pure CSS.
However, you can also consider using
<p contenteditable></p>
andp:empty
to implement the text box and its status with or without input.No, it is more appropriate to use JS to achieve this effect.
It doesn’t seem to exist at the moment, but if it does, it will definitely be more convenient than JS