css checkbox ๋ง๋ค๊ธฐ
๊ธ์๋ถ๋ถ(label) ๋ฅผ ํด๋ฆญํด๋ ์ฒดํฌ ๋๋ ์ฒดํฌ๋ฐ์ค๋ฅผ ๊ณตํต ํด๋์ค๋ก ๋ง๋ค์ด ๋ณด์ !
์ ๊ณตํตํด๋์ค๋ฅผ ์ค๊น?
์ ๋๊ทธ๋ผ๋ฏธ ์ฒดํฌ๋ฐ์ค๋ ์ด ํ์ด์ง์์๋ง ์ฐ์ด๋๊ฒ ์๋ ํํ์ด์ง ์ ์ฒด์์ ๊ณ์ ์ฐ์ผ ๋์์ธ์ด๊ธฐ ๋๋ฌธ์..!
1. html ๋ก check box ์์ฑ
<div class="agree_bottom">
<div class="checkbox_wrap">
<input id="agree1" class="blind" type="checkbox">
<label for="agree1">
๊ฐ์ธ์ ๋ณด์์ง ๋ฐ ์ด์ฉ์ ๋์ํฉ๋๋ค.
<em class="txt_point01">(ํ์)</em></label>
</div>
๊ธฐ์กด ํ ์คํธ๋ฐ์ค๋ฅผ ํฌํจํ agree_area ์ agree_wrap ์์ html์ input ํ๊ทธ ํ์ ์ checkbox๋ก ์ง์ ํด์ค๋ค.
(๋ํ ๊ธ์๋ฅผ ํด๋ฆญํ๋ฉด ์ฒดํฌ๋ฐ์ค์ ํ์๊ฐ ๋๋๋ก label์ ๊ฐ์ด ์ง์ )
- ๋ผ๋ฒจ์ ๋๋ฅด๋ฉด ์ฒดํฌ๋ฐ์ค๊ฐ ์ฒดํฌ๋์ด์ผํจ
- ์ด๋ ์ค๋ฅธ์ชฝ ๋ฐ์ค๋ flat์ผ๋ก ๋์์ค์ผ ํ๋ฏ๋ก
<div class="agree_wrap agree_right"> ์ด๋ฆ์ ๋ค๋ฅด๊ฒ ์ง์
์ด๋ ์ด๊ธฐํ ์ฝ๋๋ฅผ ์ญ์ ํด ์ฃผ์ด์ผ ์ฒดํฌ๋ฐ์ค๋ฅผ ๋ณผ์ ์์
- ํผ์์์ ๋์ด๊ฐ ๋ค๋ฅผ๋ ์์๋ผ๋ฆฌ ์ธ๋ก์ ๋ ฌ์ํด, ios ๋ฅ๊ทผ๋ชจ์๋ฆฌ, ๊ธฐ๋ณธ์คํ์ผ ์ ๊ฑฐ
- border-radius:0 -> iOS์์ ํ ๋๋ฆฌ๊ฐ ๋ฅ๊ธ๊ฒ ๋์ค๋ฏ๋ก ๋นผ์ค
- -webkit-appearance: none -> iOS์์ ํผ์์์ ๋ด๋ถ๊ทธ๋ฆผ์๊ฐ ๋์ค๋ฏ๋ก ๋นผ์ค
input, select, textarea, button {
vertical-align: middle; margin: 0;
padding: 0;
border-radius: 0;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}
2. check box ๋์์ธํ๊ธฐ
- ์ฒดํฌ๋ฐ์ค๋ ์ธํ ํผ์ด๋ฏ๋ก ์ธ๋ผ์ธ๋ธ๋ญ์ฒ๋ฆฌ
.checkbox_wrap {
display: inline-block;
}
- ๋ง์ฐ์ค ์ปค์ ๋ชจ์ ๋ณ๊ฒฝ
input[type=checkbox] + label {
color: #292929;
cursor: pointer;
position: relative;
}
- ๊พธ๋ฏธ๋ ํจ๊ณผ before๋ก ์ฒดํฌ๋ฐ์ค์ ๋ชจ์์ ๋๊ทธ๋ผ๋ฏธ๋ก ๋ณ๊ฒฝ์ค๋ค.
ํ์ ํด๋์ค ์ ํ, ํ์ ์ ํ์๋ก label ์์์ ์ ์ฉ
input[type=checkbox] + label:before {
content: '';
display: inline-block;
width: 30px;
height: 30px;
border-radius: 50%;
border: 2px solid #dddddd;
vertical-align: -10px;
margin-right: 10px;
}โ
3. checked ์์ฑ์ผ๋ก ์ฒดํฌํ ์ด๋ฏธ์ง ์ฃผ๊ธฐ
:checked ์์ฑ์ ์ฒดํฌ๊ฐ ๋์์๋์ ๋์ง ์์์๋์ ๋ด์ฉ์ ๊ตฌ๋ถํ ์ ์๋ค.
์ฒดํฌ๊ฐ ๋์์ ๋์ css ์คํ์ผ์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ค๋ฅด๊ฒ ๋์์ธํด๋ณด์

input[type=checkbox]:checked + label:before {
background: url(../images/icon_checkbox.png) no-repeat 50% 50% / 20px;
}
4. ์ ๋๋ฉ์ด์ ํจ๊ณผ๋ก ์ฒดํฌ๋ชจ์ ๋ถ๋๋ฝ๊ฒ
์ฌ์ฉ์๊ฐ ์์ ์๋๋ก ๋ง์ฐ์ค๋ฅผ ๊ฐ๋ฐ๋๋ฉด ์ปค์ ๋ชจ์์ ๋ฐ๊ฟ๋ณด์
input[type=checkbox] + label:after {
content: '';
position: absolute;
left: 6px;
top: 0;
width: 0;
height: 24px;
background: url(../images/icon_checkbox.png)no-repeat;
}
input[type=checkbox]:checked + label:after {
width: 24px;
transition: all 0.3s;
}