10.1 ๊ฐ์ ํด๋์ค :focus
CSS ๊ฐ์ ํด๋์ค๋ ์์๋ฅผ ๋ค์ํ ์ํ์์ ์คํ์ผ๋ง ํ ์ ์๋ ๋ฉ์ง ๋๊ตฌ์ผ. ์ด๊ฑธ ํ์ฉํ๋ฉด ์ฌ์ฉ์์ ์น ํ์ด์ง์ ํผ ๋ฐ ๋ค๋ฅธ ์ธํฐ๋ํฐ๋ธ ์์๋ค๊ณผ์ ์ํธ์์ฉ์ ๊ฐ์ ํ ์ ์์ด. ๊ฐ์ ํด๋์ค :focus
, :hover
, :disabled
, ๊ทธ๋ฆฌ๊ณ :checked
๋ฅผ ์
๋ ฅ ์์ (<input>
) ์คํ์ผ๋ง์ ์ด๋ป๊ฒ ์ฌ์ฉํ ์ ์๋์ง ์์๋ณด์.
:focus
๊ฐ์ ํด๋์ค๋ ํผ ์์๊ฐ ํฌ์ปค์ค๋ฅผ ๋ฐ์ ๋ ์ ์ฉ๋ผ. ๋ณดํต ์์๋ฅผ ํด๋ฆญํ๊ฑฐ๋ Tab ํค๋ฅผ ์ฌ์ฉํด ์ด๋ํ ๋ ๋ฐ์ํ์ง. ํฌ์ปค์ค๋ ์์ ์คํ์ผ๋ง์ ์ฌ์ฉ์๊ฐ ํผ์์ ๋ ์ ํ์ํ ์ ์๋๋ก ๋์์ค.
์ฌ์ฉ ์์:
input:focus {
border-color: #4A90E2;
box-shadow: 0 0 5px rgba(74, 144, 226, 0.5);
outline: none;
}
<form>
<label for="name">์ด๋ฆ:</label>
<input type="text" id="name" name="name">
</form>
์ค๋ช
border-color
: ์์๊ฐ ํฌ์ปค์ค๋ฅผ ๋ฐ์ ๋ ํ ๋๋ฆฌ ์์ ๋ณ๊ฒฝํดbox-shadow
: ์์ ์ฃผ์์ ๊ทธ๋ฆผ์ ํจ๊ณผ๋ฅผ ์ถ๊ฐํด ๊ฐ์กฐํด์คoutline
: ๊ธฐ๋ณธ ๋ธ๋ผ์ฐ์ ํ ๋๋ฆฌ๋ฅผ ์์ ๊ณ ์ปค์คํ ์คํ์ผ๋ก ๋ฐ๊ฟ์ค
10.2 ๊ฐ์ ํด๋์ค :hover
:hover
๊ฐ์ ํด๋์ค๋ ์ฌ์ฉ์๊ฐ ์์ ์์ ๋ง์ฐ์ค๋ฅผ ์ฌ๋ฆด ๋ ์ ์ฉ๋ผ. ์ด๊ฑด ์์์ ์ํธ ์์ฉํ ๋ ์๊ฐ์ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ ๋ฐ ์ ์ฉํด.
์ฌ์ฉ ์์:
input:hover {
border-color: #50E3C2;
background-color: #F0F8FF;
}
<form>
<label for="email">์ด๋ฉ์ผ:</label>
<input type="email" id="email" name="email">
</form>
์ค๋ช
border-color
: ์์ ์์ ์ปค์๊ฐ ์์ ๋ ํ ๋๋ฆฌ ์์ ๋ณ๊ฒฝํดbackground-color
: ์ปค์๊ฐ ์์ ๋ ์์์ ๋ฐฐ๊ฒฝ์์ ๋ณ๊ฒฝํด์ค
10.3 ๊ฐ์ ํด๋์ค :disabled
:disabled
๊ฐ์ ํด๋์ค๋ ๋นํ์ฑํ๋์ด ์ฌ์ฉ์์ ์ํธ์์ฉํ ์ ์๋ ํผ ์์์ ์ ์ฉ๋ผ. ์ด๊ฑด ์ฌ์ฉ์๊ฐ ์์๊ฐ ๋นํ์ฑํ๋๋ค๋ ๊ฑธ ์ดํดํ๋ ๋ฐ ๋์์ด ๋ผ.
์ฌ์ฉ ์์:
input:disabled {
background-color: #E0E0E0;
color: #A0A0A0;
cursor: not-allowed;
}
<form>
<label for="username">์ฌ์ฉ์ ์ด๋ฆ:</label>
<input type="text" id="username" name="username" disabled>
</form>
์ค๋ช
background-color
: ๋นํ์ฑํ๋ ์์์ ๋ฐฐ๊ฒฝ์์ ๋ณ๊ฒฝํด ๋นํ์ฑํ ์ํ๋ฅผ ๋ํ๋ดcolor
: ๋นํ์ฑํ๋ ์์ ์์ ํ ์คํธ ์์ ๋ณ๊ฒฝํดcursor
: "not-allowed" ์ํ๋ก ์ปค์๋ฅผ ์ค์ ํด ์์๊ฐ ์ฌ์ฉ ๋ถ๊ฐ์์ ์๊ฐ์ ์ผ๋ก ๋ํ๋ด์ค
10.4 ๊ฐ์ ํด๋์ค :checked
:checked
๊ฐ์ ํด๋์ค๋ checkbox
์ radio
ํ์
์์ ์ ํ๋ ์ํ์ ์์ ๋ ์ ์ฉ๋ผ. ์ด๊ฑด ์ ํ๋ ์์๋ฅผ ์คํ์ผ๋งํด์ ๋ ๋์ ๋๊ฒ ๋ง๋ค์ด ์ค.
์ฌ์ฉ ์์:
input[type="checkbox"]:checked,
input[type="radio"]:checked {
background-color: #4A90E2;
border-color: #4A90E2;
}
<form>
<label>
<input type="checkbox" name="option" checked>
์ต์
1
</label>
<label>
<input type="checkbox" name="option">
์ต์
2
</label>
<label>
<input type="radio" name="choice" checked>
์ ํ 1
</label>
<label>
<input type="radio" name="choice">
์ ํ 2
</label>
</form>
์ค๋ช
background-color
: ์ ํ๋ ์์์ ๋ฐฐ๊ฒฝ์์ ๋ณ๊ฒฝํดborder-color
: ์ ํ๋ ์์์ ํ ๋๋ฆฌ ์์ ๋ณ๊ฒฝํด์ค
GO TO FULL VERSION