Bootstrap 4 / 체크박스, 라디오 버튼 꾸미기

Bootstrap을 이용하면 체크박스와 라디오 버튼을 쉽게 꾸밀 수 있습니다. 두 가지 방법을 소개합니다.

방법 1

<!doctype html>
<html lang="ko">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Bootstrap 4</title>
		<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
		<style>
			p { margin:20px 0px; }
		</style>
	</head>
	<body>
		<div class="container">
			<div class="row">
				<div class="col">
					<p><strong>Checkbox</strong></p>
					<div class="custom-control custom-checkbox">
						<input type="checkbox" id="jb-checkbox" class="custom-control-input">
						<label class="custom-control-label" for="jb-checkbox">Checkbox</label>
					</div>
					<p><strong>Radio Button</strong></p>
					<div class="custom-control custom-radio">
						<input type="radio" name="jb-radio" id="jb-radio-1" class="custom-control-input">
						<label class="custom-control-label" for="jb-radio-1">Radio Button 1</label>
					</div>
					<div class="custom-control custom-radio">
						<input type="radio" name="jb-radio" id="jb-radio-2" class="custom-control-input">
						<label class="custom-control-label" for="jb-radio-2">Radio Button 2</label>
					</div>
				</div>
			</div>
		</div>
		<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
		<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
	</body>
</html>

선택하기 전의 모습입니다.

선택한 후의 모습니다.

방법 2

<!doctype html>
<html lang="ko">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Bootstrap 4</title>
		<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
		<style>
			p { margin:20px 0px; }
		</style>
	</head>
	<body>
		<div class="container">
			<div class="row">
				<div class="col">
					<p><strong>Checkbox</strong></p>
					<div class="btn-group-toggle" data-toggle="buttons">
						<label class="btn btn-primary">
							<input type="checkbox"> Checkbox
						</label>
					</div>
					<p><strong>Radio Button</strong></p>
					<div class="btn-group btn-group-toggle" data-toggle="buttons">
						<label class="btn btn-danger">
							<input type="radio" name="jb-radio" id="jb-radio-1"> Radio Button 1
						</label>
						<label class="btn btn-danger">
							<input type="radio" name="jb-radio" id="jb-radio-2"> Radio Button 2
						</label>
						<label class="btn btn-danger">
							<input type="radio" name="jb-radio" id="jb-radio-3"> Radio Button 3
						</label>
					</div>
				</div>
			</div>
		</div>
		<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
		<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
	</body>
</html>

선택하기 전의 모습니다.

선택한 후의 모습입니다. 선택하면 색이 진해집니다.

btn-primary를 변경해서 색을 바꿀 수 있습니다. 가능한 값은 btn-primary, btn-secondary, btn-success, btn-danger, btn-warning, btn-info, btn-light, btn-dark입니다.