아는 것이 좋은 것이다.

[CSS] 체크박스 이미지 변환 본문

CSS

[CSS] 체크박스 이미지 변환

start0 2016. 2. 13. 22:58
<html>
<head>
<title>체크 박스 이미지로 구현</title>
</head>
<body>
<style type="text/css">
    .custom_checkbox {position:relative; margin:45px 0 0 20px;}
    label.image_checkbox {position:absolute; left:0; height:26px; padding:4px 0 0 30px; background:url('이미지경로') no-repeat;}
    input[type="checkbox"]:checked.image_checkbox + label.image_checkbox {background-position:0 -30px;}
</style>
    <div class="custom_checkbox">
        <h2>커스텀 체크박스</h2>
        <input type="checkbox" id="custom" name="normal" class="image_checkbox">
        <label for="custom" class="image_checkbox">커스텀 체크박스1</label>
        <br><br>
        <input type="checkbox" id="custom2" name="normal" class="image_checkbox">
        <label for="custom2" class="image_checkbox">커스텀 체크박스2</label>
    </div>
</body>

</html>



* 이미지를 박아 넣고 클릭시 위아래로 이미지가 이동하여 체크가 된건지 안된건지 이미지로 구분 가능


 

이런식의 이미지를 만든후 위의 CSS 백그라운드에 경로지정하여 넣어주면 된다. 사이즈는 해당 이미지에 맞게 조절하면 된다.

(위의 ○는 체크해제 이미지, 아래 ●는 체크된 이미지)

Comments