有没有用CSS将单选按钮变大的方法?
如果没有,有什么其他方法可以做到?
如果没有,有什么其他方法可以做到?
试试这段代码:
input[type='radio'] {
transform: scale(2);
}
您可以像其他元素一样轻松设置其高度和宽度。
这是带有代码的fiddle
HTML
<input id="r1" type="radio" name="group1" class="radio1" />
<label for="r1">label 1 text</label>
<input id="r2" type="radio" name="group1" class="radio2" />
<label for="r2">label 2 text</label>
<input id="r3" type="radio" name="group1" class="radio3" />
<label for="r3">label 3 text</label>
<input id="r4" type="radio" name="group1" class="radio4" />
<label for="r4">label 4 text</label>
CSS
input[type=radio] {
display: none;
}
input[type=radio] + label::before {
content: '';
display: inline-block;
border: 1px solid #000;
border-radius: 50%;
margin: 0 0.5em;
}
input[type=radio]:checked + label::before {
background-color: #ffa;
}
.radio1 + label::before {
width: 0.5em;
height: 0.5em;
}
.radio2 + label::before {
width: 0.75em;
height: 0.75em;
}
.radio3 + label::before {
width: 1em;
height: 1em;
}
.radio4 + label::before {
width: 1.5em;
height: 1.5em;
}
美化单选按钮并不容易。
通常情况下,表单元素使用CSS alone
无法进行样式设置,要想实现美化需要其他方法。
你可以通过访问以下链接获得自己所需的具有更大尺寸的单选按钮样式。
同时,也可以查看以下链接...
不要使用transform: scale(1.3)
,这样看起来非常糟糕。只需使用此代码:
input[type='radio'] {
height: 15px;
width: 15px;
vertical-align: middle;
}
<input type="radio">Select this item
HTML
<label>
<input type="radio" value="1">
<div></div>
</label>
input[type="radio"] {
display: none;
}
input[type="radio"] + div {
height: 20px;
width: 20px;
display: inline-block;
cursor: pointer;
vertical-align: middle;
background: #FFF;
border: 1px solid #d2d2d2;
border-radius: 100%;
}
input[type="radio"] + div:hover {
border-color: #c2c2c2;
}
input[type="radio"]:checked + div {
background:gray;
}
CSS3变换缩放会模糊。在FF中设置高度和宽度无效(即使最新的66版本也不支持,2020年)。唯一的跨浏览器解决方案是使用自定义HTML标记+CSS,但这并不是最简单的方法。请参阅有用的教程自定义单选框和复选框。
input
元素的样式),而在您提供的链接中,OP提出了更大的“可点击”区域(解决方法是改变label
的样式)。 相反,在此处,有回答适用于在此问题中提出的OP的问题的答案。 最快的答案((c) imanabidi)--“设置宽度和高度,使用em度量单位,例如:width: 1.2em; height: 1.2em”。 - trejder