�ómo crear: 사용자 정의 체크 박스
- 이전 페이지 네비게이션 바에 있는 로그인 양식
- 다음 페이지 사용자 정의 선택 상자
CSS를 사용하여 사용자 정의 체크 박스와 단일 선택 버튼을 배우는 방법.
기본:
OneTwo
One
Two
사용자 정의 체크 박스:
사용자 정의 단일 선택 버튼:
사용자 정의 체크 박스 생성 방법
第一步 - HTML 추가:
<label class="container">One <input type="checkbox" checked="checked"> <span class="checkmark"></span> </label> <label class="container">Two <input type="checkbox"> <span class="checkmark"></span> </label> <label class="container">Three <input type="checkbox"> <span class="checkmark"></span> </label> <label class="container">Four <input type="checkbox"> <span class="checkmark"></span> </label>
第二步 - CSS 추가:
/* 사용자 정의 태그(컨테이너) */ .container { display: block; position: relative; padding-left: 35px; margin-bottom: 12px; cursor: pointer; font-size: 22px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* 브라우저 기본 체크 박스 숨기기 */ .container input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; } /* 사용자 정의 체크 박스 생성 */ .checkmark { position: absolute; top: 0; left: 0; height: 25px; width: 25px; background-color: #eee; } /* 마우스 오버 시, 회색 배경색 추가 */ .container:hover input ~ .checkmark { background-color: #ccc; } /* 체크 박스 선택 후 파란 배경 추가 */ .container input:checked ~ .checkmark { background-color: #2196F3; } /* 체크 표시자/지시자 생성 (선택되지 않았을 때 숨기기) */ .checkmark:after { content: ""; position: absolute; display: none; } /* 선택될 때 체크 표시자 표시 */ .container input:checked ~ .checkmark:after { display: block; } /* 설정 체크 표시자/지시자 스타일 */ .container .checkmark:after { left: 9px; top: 5px; width: 5px; height: 10px; border: solid white; border-width: 0 3px 3px 0; -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); }
사용자 정의 단일 선택 버튼 생성 방법
예제
/* 사용자 정의 태그(컨테이너) */ .container { display: block; position: relative; padding-left: 35px; margin-bottom: 12px; cursor: pointer; font-size: 22px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* 브라우저의 기본 단일 선택 버튼 숨기기 */ .container input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; } /* 사용자 정의 단일 선택 버튼 생성 */ .checkmark { position: absolute; top: 0; left: 0; height: 25px; width: 25px; background-color: #eee; border-radius: 50%; } /* 마우스 오버 시, 회색 배경색 추가 */ .container:hover input ~ .checkmark { background-color: #ccc; } /* 단일 선택 버튼이 선택될 때, 파란색 배경 추가 */ .container input:checked ~ .checkmark { background-color: #2196F3; } /* 설정지시자(점/원 - 선택되지 않았을 때 숨기기) */ .checkmark:after { content: ""; position: absolute; display: none; } /* 선택될 때 설정지시자(점/원) 표시 */ .container input:checked ~ .checkmark:after { display: block; } /* 설정지시자 스타일(점/원) */ .container .checkmark:after { top: 9px; left: 9px; width: 8px; height: 8px; border-radius: 50%; background: white; }
- 이전 페이지 네비게이션 바에 있는 로그인 양식
- 다음 페이지 사용자 정의 선택 상자