整合營銷服務(wù)商

          電腦端+手機端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          純css美化單選框(radio)樣式

          純css美化單選框(radio)樣式
          <!DOCTYPE html>
          <html lang="en">
          <head>
           <meta charset="UTF-8">
           <style>
           label{
           margin:5px;
           }
           .input-radio{
           display: none;
           }
           .span-radio{
           display: inline-block;
           border:1px solid #ccc;
           width:16px;
           height: 16px;
           border-radius:2px;
           vertical-align: middle;
           margin-right: 5px;
           position: relative;
           }
           .span-radio:before{
           content: '';
           font-size: 0;
           width: 10px;
           height: 10px;
           background: blue;
           position: absolute;
           left:50%;
           top:50%;
           margin-left: -5px;
           margin-top: -5px;
           border-radius: 2px;
           display: none;
           }
           /* ~代表選擇checked的后面的兄弟節(jié)點,顯示選中背景框*/
           .input-radio:checked~.span-radio:before{
           display: block;
           }
           </style>
          </head>
          <body>
          <label>
           <input type="radio" name="evaluate" id="radio1" class="input-radio">
           <span class="span-radio"></span>優(yōu)
          </label>
          <label>
           <input type="radio" name="evaluate" id="radio2" class="input-radio">
           <span class="span-radio"></span>良
          </label>
          <label>
           <input type="radio" name="evaluate" id="radio3" class="input-radio">
           <span class="span-radio"></span>中
          </label>
          </body>
          </html>
          

          果圖

          天和大家分享如何修改radio樣式

          效果

          自定義顏色

          自定義圖片

          代碼

          全部代碼直接可以運行,兼容性ie,火狐,谷歌

          景:自帶的單選按鈕真的是很不好看,這時候需要radio的自定義美化





          Html 布局
           <ul class="prize-choose">
              <?php foreach ($goods as $key=> $data){?>
                  <li class="item">
                    //選中區(qū)域的熱區(qū)
                        <label for="radio<?=$key +1 ?>" style="display: block;">
                        <img src="">
                        <p><?=!empty($data['name'])?$data['name']:'暫無名稱'?></p>
                        <div class="detail"><?=$data['detail']?></div>
                        <div class="price">
                            <p>
                            	<span class="now_price"><?=$data['sale_price']?></span>
                                  <del>¥<?=$data['fix_price']?></del>
                            </p>
                            <div class="prize-radio" goods-price="<?=$data['sale_price']?>" goods-id="<?=$data['goods_id']?>">
                               <input type="radio" id="radio<?=$key +1 ?>" name="prizeradio">
                               <label for="radio<?=$key +1 ?>"></label>
                            </div>
                       </div>
                    </label>
                </li>
            <?php }?>
           </ul>
          
          單選的局部代碼 //常規(guī)狀態(tài)
          <div class="prize-radio">
            <input type="radio" id="radio<?=$key +1 ?>" name="prizeradio">
            <label for="radio<?=$key +1 ?>"></label>
          </div>
          
          //選中狀態(tài),同radio
          <input type="checkbox" id="awesome1" checked>
           //常規(guī)不可點
           <input type="checkbox" id="awesome2" disabled>
           //選中不可點擊
           <input type="checkbox" id="awesome3" disabled class="checked">
          css 美化
          .prize-radio{
                input[type="radio"] {
                  position: absolute;
                  clip: rect(0, 0, 0, 0);
                }
                input[type="radio"] + label {
                  cursor: pointer;
                  position: relative;
                  line-height: 12px;
                  user-select: none;
                }
                input[type="radio"] + label:not(:nth-of-type(1)) {
                  margin-top: 29px;
                  margin-bottom: 29px;
                }
                input[type="radio"]:checked + label{
                  color: #0091FF;
                }
              //單選框的樣式
                input[type="radio"] + label::before{
                  content: "";
                  display: inline-block;
                  width: 24px; height: 24px;
                  border-radius: 50%;
                  vertical-align: top;
                  margin-right: .2em;
                  border: 1px solid #ccc;
                  background-color: #fff;
                  transition: border-color .2s ease-in-out, background-color .2s ease-in-out;
                }
                input[type="radio"]:not(:disabled) + label:hover::before{
                  border-color: #0091FF;
                }
              //(制作樣式1)對勾樣式制作1 
                input[type="radio"] + label::after{
                  content: "";
                  display: inline-block;
                  width: 5px;
                  height: 13px;
                  border: 2px solid #fff;
                  border-top: 0;
                  border-left: 0;
                  position: absolute;
                  left: 9px;
                  top: 3px;
                  transform: rotate(45deg) scale(0);
                  transition: all .2s ease-in-out;
                }
                input[type="radio"]:checked + label::before{
                  border-color: #0091FF !important;
                  background-color: #0091FF;
                }
                input[type="radio"]:checked + label::after{
                  transform: rotate(45deg) scale(1);
                  transition: all .2s ease-in-out;
                }
              //不可點擊的背景色設(shè)置-----不常用
              input[type="checkbox"]:disabled + label::before,
              input[type="checkbox"]:disabled.checked + label::before{
                background-color: #f2f2f2;
              }
            //不可點擊的文本框?qū)搭伾O(shè)置--不常用
              input[type="checkbox"]:disabled.checked + label::after{
                border-color: #ccc;
                transform: rotate(45deg) scale(1);
              }
            //****制作樣式1 end******
            
              //***(制作樣式2)圓圈
            //after單選框中間的選中效果
            input[type="radio"] + label::after {
              content: "";
              display: inline-block;
              width: 4px;
              height: 4px;
              background-color: #fff;
              border-radius: 4px;
              position: absolute;
              left: 4px; top: 50%;
              transform: translateY(-50%) scale(0);
              transition: transform .2s ease-in-out;
            }
          
            input[type="radio"]:checked + label::after {
              transform: translateY(-50%) scale(1);
              transition: transform .2s ease-in-out;
            }
            //disabled 不常用
            input[type="radio"]:disabled + label::before,
            input[type="radio"]:disabled.checked + label::before {
              background-color: #f2f2f2;
            }
            //不常用
            input[type="radio"]:disabled.checked + label::after {
              border-color: #ccc;
              background-color: #ccc;
              transform: translateY(-50%) scale(1);
            }
            //****制作樣式2 end******
          }

          js傳參數(shù)操作:尤其涉及到交互,需要把選中商品的的id呀,價格呀,傳遞給后臺,這時候就常用的東西都如下操作啦


          主站蜘蛛池模板: 日韩欧国产精品一区综合无码| 日韩精品无码久久一区二区三| 精品福利一区3d动漫| 一区二区三区四区无限乱码| 国产一区二区三区在线电影| 国产精品伦一区二区三级视频| 色噜噜一区二区三区| 一区二区高清在线| 国产一区二区内射最近更新| 亚洲国产精品自在线一区二区| 亚洲一区动漫卡通在线播放| 精品国产福利在线观看一区| www.亚洲一区| 精品国产一区二区麻豆| 国模无码人体一区二区| 无码国产精品一区二区免费16 | 无码人妻一区二区三区av| 亚洲高清成人一区二区三区| 精品国产鲁一鲁一区二区| 中文字幕在线视频一区| 日本视频一区在线观看免费| 久久久久人妻一区精品果冻| 久久久无码一区二区三区| 风流老熟女一区二区三区| 国产经典一区二区三区蜜芽| 一区二区国产精品| 女人18毛片a级毛片一区二区| 又硬又粗又大一区二区三区视频| 免费高清av一区二区三区| 亚洲av乱码一区二区三区香蕉| 国产美女精品一区二区三区| 国产AV天堂无码一区二区三区| 国产成人久久精品区一区二区| 一本AV高清一区二区三区| 一区二区三区在线视频播放| 韩国精品福利一区二区三区| 中字幕一区二区三区乱码| 亚洲美女一区二区三区| 亚洲av鲁丝一区二区三区| 国产成人精品无码一区二区三区 | 国产情侣一区二区|