單選-複選按鈕自定義樣式

通過”:checked“配合其他標籤來自定義複選框樣式

Html代碼:

<form action="#">
			<div class="wrapper">
				<div class="box">
					<input type="checkbox" checked="checked" id="username" />
					<span>√</span>
				</div>
				<label for="username">我是選中狀態</label>
			</div>
			
			<div class="wrapper">
				<div class="box">
					<input type="checkbox"  id="userpwd" />
					<span>√</span>
				</div>
				<label for="userpwd">我是未選中狀態</label>
			</div>
			
		</form>
Css代碼:

form{ border:1px solid #ccc; padding: 20px; width: 300px; margin: 30px auto;}
			.wrapper{ margin-bottom: 10px;}
			.box{ display: inline-block; width:20px; height: 20px; position: relative;
				border: 2px solid orange; margin-right: 5px; vertical-align:middle;
			}
			.box input{ opacity: 0; position: absolute; top:0; left: 0;}
			.box span{ 
				 position: absolute; top: -10px; right: 3px;
				 font-size: 30px;  font-weight: bold;  font-family: Arial;
			     -webkit-transform: rotate(30deg); transform: rotate(30deg); color: orange;
			}
			input[type="checkbox"] + span{ opacity: 0;}
			input[type="checkbox"]:checked + span{ opacity:1;}






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章