--- title: ':read-only' slug: 'Web/CSS/:read-only' tags: - CSS - Layout - Pseudo-class - Reference - Web translation_of: 'Web/CSS/:read-only' ---
La pseudo-class CSS :read-only representa un element (com ara una entrada de text bloquejat) que no és editable per l'usuari.
/* Selecciona qualsevol element <input> que sigui de només lectura Compatible amb Firefox amb un prefix */ input:-moz-read-only { background-color: #ccc; } /* Compatible amb Blink/WebKit/Edge sense un prefix */ input:read-only { background-color: #ccc; }
Nota: Aquest selector no només selecciona {{htmlElement("input")}}s amb {{htmlattrxref("readonly", "input")}} establerts en ells; seleccionarà qualsevol element que no pugui ser editat per l'usuari.
{{csssyntax}}
<input type="text" value="Type whatever you want here."> <input type="text" value="This is a read-only field." readonly> <p>This is a normal paragraph.</p> <p contenteditable="true">You can edit this paragraph!</p>
input { min-width: 25em; }
input:-moz-read-only { background: cyan; }
input:read-only { background: cyan; }
p:-moz-read-only { background: lightgray; }
p:read-only { background: lightgray; }
p[contenteditable="true"] { color: blue; }
{{EmbedLiveSample("Example")}}
| Especificació | Estat | Comentari |
|---|---|---|
| {{ SpecName('HTML WHATWG', '#selector-read-only', ':read-only') }} | {{ Spec2('HTML WHATWG') }} | Sense canvis. |
| {{ SpecName('HTML5 W3C', '#selector-read-only', ':read-only') }} | {{ Spec2('HTML5 W3C') }} | Defineix la semàntica respecte a l'HTML i la validació de restriccions. |
| {{ SpecName('CSS4 Selectors', '#rw-pseudos', ':read-only') }} | {{ Spec2('CSS4 Selectors') }} | Defineix la pseudo-classe, però no la semàntica associada. |
{{Compat("css.selectors.read-only")}}