:disabled
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
CSS :disabled ìì¬ í´ëì¤ë 모ë ë¹íì± ìì를 ëíë
ëë¤. ë¹íì± ììë íì±(ì í, í´ë¦, ì
ë ¥ ë±ë±)íê±°ë í¬ì»¤ì¤ë¥¼ ë°ì ì ìë ìì를 ë§í©ëë¤. ë°ë ìíì¸ íì± ììë ì¡´ì¬í©ëë¤.
ìëí´ ë³´ê¸°
label {
display: block;
margin-top: 1em;
}
*:disabled {
background-color: dimgrey;
color: linen;
opacity: 1;
}
<form>
<label for="name">Name:</label>
<input id="name" name="name" type="text" />
<label for="emp">Employed:</label>
<select id="emp" name="emp" disabled>
<option>No</option>
<option>Yes</option>
</select>
<label for="empDate">Employment Date:</label>
<input id="empDate" name="empDate" type="date" disabled />
<label for="resume">Resume:</label>
<input id="resume" name="resume" type="file" />
</form>
구문
css
:disabled {
/* ... */
}
ìì
ë¤ì ìì ë ì¬ì©ìê° ì²êµ¬ 주ì ì
ë ¥ 칸ì ì¼ê±°ë ë ì ìë 기ë¥ì JavaScript change ì´ë²¤í¸ë¥¼ íµí´ 구íí 기본ì ì¸ ë°°ì¡ ììì
ëë¤.
HTML
html
<form action="#">
<fieldset id="shipping">
<legend>ë°°ì¡ì§</legend>
<input type="text" placeholder="ì´ë¦" />
<input type="text" placeholder="주ì" />
<input type="text" placeholder="ì°í¸ë²í¸" />
</fieldset>
<br />
<fieldset id="billing">
<legend>ì²êµ¬ì§</legend>
<label for="billing-checkbox">ë°°ì¡ì§ì ëì¼:</label>
<input type="checkbox" id="billing-checkbox" checked />
<br />
<input type="text" placeholder="ì´ë¦" disabled />
<input type="text" placeholder="주ì" disabled />
<input type="text" placeholder="ì°í¸ë²í¸" disabled />
</fieldset>
</form>
CSS
css
input[type="text"]:disabled {
background: #ccc;
}
JavaScript
ì²´í¬ë°ì¤ë¥¼ í´ë¦í ëë§ë¤ ì ë ¥ íëì íì± ìíê° ì íë©ëë¤.
js
const checkbox = document.querySelector("#billing-checkbox");
const billingItems = document.querySelectorAll('#billing input[type="text"]');
checkbox.addEventListener("change", () => {
billingItems.forEach((item) => {
item.disabled = !item.disabled;
});
});
ê²°ê³¼
ì²´í¬ë°ì¤ë¥¼ ì²´í¬íê±°ë í´ì í´ ì²êµ¬ íëì ì¤íì¼ì ë³ê²½í´ ë³´ì¸ì.
ëª ì¸
| Specification |
|---|
| HTML > # selector-disabled > |
| Selectors Level 4 > # disabled-pseudo > |