css3將radio單選按鈕模擬為按鈕形狀

antzone發表於2017-03-23

在很多時候,單選按鈕以按鈕形式展現更加美觀。

如下圖所示:

a:3:{s:3:\"pic\";s:43:\"portal/201703/23/095202f4quyx9xhf9q8pfu.png\";s:5:\"thumb\";s:0:\"\";s:6:\"remote\";N;}

下面分享一段程式碼例項,它就實現了類似的功能。

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
*{
  margin: 0;
  padding: 0;
}
body{
  background: #f1f1f1;
}
li{
  list-style: none;
}
.item {
  width: 25%;
  height: 44px;
  line-height: 44px;
  font-size: 15px;
  overflow: hidden;
  float: left;
  text-align: center;
  margin-bottom: 10px;
}
.item .type {
  height: 41px;
  line-height: 41px;
  text-align: center;
  background-color: #fff;
  font-size: 15px;
  display: block;
  margin: 0 5px;
}
.radio {
  position: absolute;
  top: -9999px;
}
.item .type span {
  height: 39px;
  display: block;
  border: 1px solid #fff;
  display: block;
  position: relative;
}
 .item .radio:checked ~ span {
  color: #74c742;
  border-color: #74c742;
}
</style>
</head>
<body>
<ul>
  <li class="item">
    <label class="type">
      <input type="radio" class="radio" name="style" value="4">
      <span>螞蟻部落一<i class="check-icon"></i></span>
    </label>
  </li>
  <li class="item">
    <label class="type">
      <input type="radio" class="radio" name="style" value="4">
      <span>螞蟻部落二<i class="check-icon"></i></span>
    </label>
  </li>
</ul>
</body>
</html>

相關文章