如何將html的radio單選框自定義樣式為正方形和對(duì)號(hào)
發(fā)布時(shí)間:2023-12-14 16:50:23 作者:_小鄭有點(diǎn)困了
我要評(píng)論
如何能把html的<input type="radio" name="option">改成自定義的樣式呢?比如想要把他變成正方形,選中的時(shí)候是對(duì)號(hào),默認(rèn)的樣式太丑了,今天給大家分享如何將html的radio單選框自定義樣式為正方形和對(duì)號(hào),感興趣的朋友一起看看吧
將html的radio單選框自定義樣式為正方形和對(duì)號(hào)
背景:
如何能把html的
<input type="radio" name="option">改成自定義的樣式呢?比如想要把他變成正方形,選中的時(shí)候是對(duì)號(hào)。默認(rèn)的樣式太丑了
默認(rèn)樣式:

自定義樣式:

實(shí)現(xiàn)代碼
<!DOCTYPE html>
<html>
<head>
<style>
input[type="radio"] {
display: none;
}
.square-radio {
display: flex;
position: relative;
width: 20px;
height: 20px;
border: 2px solid #333;
cursor: pointer;
}
.square-radio::after {
content: "?";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 14px;
color: #333;
display: none;
}
input[type="radio"]:checked + .square-radio::after {
color: #2196F3;
display: block;
}
</style>
</head>
<body>
<div class="box">
性別:
<label>
男
<input type="radio" name="option">
<span class="square-radio"></span>
</label>
<label>
女
<input type="radio" name="option">
<span class="square-radio"></span>
</label>
</div>
</body>
</html>到此這篇關(guān)于如何將html的radio單選框自定義樣式為正方形和對(duì)號(hào)的文章就介紹到這了,更多相關(guān)html radio單選框自定義樣式內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
HTML的checkbox和radio樣式美化的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇HTML的checkbox和radio樣式美化的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-08html中radio值的獲取、賦值、注冊(cè)事件示例詳解
這篇文章主要介紹了html中radio值的獲取、賦值及注冊(cè)事件,非常適合新手朋友,喜歡html的朋友不要錯(cuò)過(guò)了哈2014-05-13

