When utilizing the read-only
selector, keep in mind that it doesn't exclusively target input elements; it also applies to any element that the user cannot edit, such as a div.
In a response by @TemaniAfif, the use of contenteditable
allows for making the div editable while supporting both the read-only
and disable
attributes. If you prefer not to go this route (perhaps due to control by JQuery or another framework), employing classes is an alternative approach:
.input {
color: red;
}
input.input:not(:disabled, :read-only):hover,
.input:not(input, .disabled, .read-only):hover {
color: blue;
}
<input class="input" type="text" value="input">
<input class="input" disabled type="text" value="disabled input">
<div class="input">div</div>
<div class="input disabled">disabled div</div>
<div class="input read-only">read-only div</div>