自定义常用input表单元素二:纯css实现自定义radio单选按钮
生活随笔
收集整理的這篇文章主要介紹了
自定义常用input表单元素二:纯css实现自定义radio单选按钮
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這是接著上一篇純css自定義復選框checkbox的第二篇,自定義一個radio單選按鈕,同樣,采用css偽類和“+”css選擇器為思路,下面是預覽圖:
?
下面直入主題放代碼:HTML部分
<!--兩個name相同的radio--> <input type="radio" id="my_radio1" class="my_radio" name="my_radio"><label for="my_radio1">單選Radio1</label> <br /> <input type="radio" id="my_radio2" class="my_radio" name="my_radio"> <label for="my_radio2">單選Radio2</label>HTML代碼沒什么說的,就是普通的label和input,定義相同的name即可。
下面為CSS部分:
/*radio單選主要樣式*/ .my_radio{opacity: 0;} .my_radio+label::before {content: "";display: block;width: 16px;height: 16px;border-radius: 100%;border: 1px solid #d9d9d9;position: absolute;top: 3px;left: -24px;box-sizing: border-box; }.my_radio:hover+label::before {-webkit-transition: all .3s;transition: all .3s;border-color: #1890ff }.my_radio:checked+label::after {content: "";display: block;width: 8px;height: 8px;border-radius: 100%;background-color: #1890ff;position: absolute;top: 7px;left: -20px;border-color: #1890ff;-webkit-transition: all .3s;transition: all .3s; }四行css,第二行為radio最外層的圓圈,第四行為radio最里面選中時的實心圓。第三行為radio hover時的效果。其他樣式自己可根據需要修改。
?
轉載于:https://www.cnblogs.com/websharehome/p/9622090.html
總結
以上是生活随笔為你收集整理的自定义常用input表单元素二:纯css实现自定义radio单选按钮的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 保留5位小数_小猿圈分享-M
- 下一篇: API函数的调用(包含一个大小写的问题)