一款用HTML5实现的Checkbox / Radio选择效果

  • 一款用HTML5实现的Checkbox / Radio选择效果,类似开关,鼠标点击选中的时候,会向右拨动,现在手机上很流行的一种开关效果,用HTML5可以很轻松就实现 ,学习HTML5的可不要错过这个Checkbox复选框 / Radio单选框效果。

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>html5类似开关的Checkbox / Radio</title>
<style>html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
  display: block;
}
body {
  line-height: 1;
}
ol, ul {
  list-style: none;
}
blockquote, q {
  quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
  content: '';
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
/* CHECKBOXES */
#check_frame {
  position: absolute;
  top: -75px; left: 0; right: 0; bottom: 0;
  width: 150px; height: 40px;
  padding: 10px; margin: auto;
  border: 1px solid #EEE;
}
#check_frame .checkbox { display: none; }
#check_frame  .trigger {
  cursor: pointer;
  position: relative;
  float: left;
  width: 30px; height: 20px;
  margin: 10px;
  background: #666;
  overflow: hidden;
  -webkit-transition: background .15s linear;
}
#check_frame .checkbox:checked + .trigger { background: #00C5FF; }
#check_frame .trigger:before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 10px; height: 10px;
  margin: auto 5px;
  box-shadow: 0 0 0 100px hsla(0, 0%, 0%, .3);
  -webkit-transition: left .15s linear;
}
#check_frame .checkbox:checked + .trigger:before { left: 10px; }
/* RADIO BUTTONS */
#radio_frame {
  position: absolute;
  top: 75px; left: 0; right: 0; bottom: 0;
  width: 150px; height: 40px;
  padding: 10px; margin: auto;
  border-radius: 40px;
  border: 1px solid #EEE;
}
#radio_frame .radio { display: none; }
#radio_frame  .trigger {
  cursor: pointer;
  position: relative;
  float: left;
  width: 30px; height: 20px;
  margin: 10px;
  border-radius: 20px;
  background: #666;
  overflow: hidden;
  -webkit-transition: background .15s linear;
}
#radio_frame .radio:checked + .trigger { background: #00C5FF; }
#radio_frame .trigger:before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 10px; height: 10px;
  margin: auto 5px;
  border-radius: 100%;
  box-shadow: 0 0 0 100px hsla(0, 0%, 0%, .3);
  -webkit-transition: left .15s linear;
}
#radio_frame .radio:checked + .trigger:before { left: 10px; }</style>
</head>
<body>
<section id="check_frame">
<input id="check_1" class="checkbox" name="check" type="checkbox" checked>
<label for="check_1" class="trigger"></label>
<input id="check_2" class="checkbox" name="check" type="checkbox">
<label for="check_2" class="trigger"></label>
<input id="check_3" class="checkbox" name="check" type="checkbox">
<label for="check_3" class="trigger"></label>
</section>
<section id="radio_frame">
<input id="radio_1" class="radio" name="radio" type="radio" checked>
<label for="radio_1" class="trigger"></label>
<input id="radio_2" class="radio" name="radio" type="radio">
<label for="radio_2" class="trigger"></label>
<input id="radio_3" class="radio" name="radio" type="radio">
<label for="radio_3" class="trigger"></label>
</section>
</body>
</html>

 

posted @ 2017-09-12 15:09  小牧临风  阅读(251)  评论(0编辑  收藏  举报