是否可以跨浏览器使用CSS或HTML设置复选框的大小?
width和size在IE6+中有效,但在Firefox中无效,在Firefox中,即使我设置较小的大小,复选框仍然保持16x16。
是否可以跨浏览器使用CSS或HTML设置复选框的大小?
width和size在IE6+中有效,但在Firefox中无效,在Firefox中,即使我设置较小的大小,复选框仍然保持16x16。
当前回答
默认情况下,复选框的外观似乎是固定的。但Worthy7指出,这可以补救使用CSS外观属性。它将使复选框完全为空,因此您可以定义自己的外观。这样做的好处是:您可以使用现有的HTML代码。缺点:这是一项实验技术。Edge (legacy)和IE不使用自定义样式。
下面是需要的CSS样式:
input[type=checkbox] { width: 14mm; -webkit-appearance: none; -moz-appearance: none; height: 14mm; border: 0.1mm solid black; } input[type=checkbox]:checked { background-color: lightblue; } input[type=checkbox]:checked:after { margin-left: 4.3mm; margin-top: -0.4mm; width: 3mm; height: 10mm; border: solid white; border-width: 0 2mm 2mm 0; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); content: ""; display: inline-block; } <label><input type="checkbox"> Test</label>
截图:
铬:
Firefox:
优势:
边缘(遗留):
IE:
其他回答
我认为最简单的解决方案是像一些用户建议的那样重新设置复选框的样式。下面的CSS为我工作,只需要几行CSS,并回答OP问题:
input[type=checkbox] {
-webkit-appearance: none;
-moz-appearance: none;
vertical-align: middle;
width: 14px;
height: 14px;
font-size: 14px;
background-color: #eee;
}
input[type=checkbox]:checked:after {
position: relative;
bottom: 3px;
left: 1px;
color: blue;
content: "\2713"; /* check mark */
}
正如这篇文章中提到的,缩放属性似乎在Firefox上不起作用,并且转换可能会导致不希望看到的效果。
在Chrome和Firefox上测试,应该适用于所有现代浏览器。只需根据需要更改属性(颜色、大小、底部、左侧等)。希望能有所帮助!
默认情况下,复选框的外观似乎是固定的。但Worthy7指出,这可以补救使用CSS外观属性。它将使复选框完全为空,因此您可以定义自己的外观。这样做的好处是:您可以使用现有的HTML代码。缺点:这是一项实验技术。Edge (legacy)和IE不使用自定义样式。
下面是需要的CSS样式:
input[type=checkbox] { width: 14mm; -webkit-appearance: none; -moz-appearance: none; height: 14mm; border: 0.1mm solid black; } input[type=checkbox]:checked { background-color: lightblue; } input[type=checkbox]:checked:after { margin-left: 4.3mm; margin-top: -0.4mm; width: 3mm; height: 10mm; border: solid white; border-width: 0 2mm 2mm 0; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); content: ""; display: inline-block; } <label><input type="checkbox"> Test</label>
截图:
铬:
Firefox:
优势:
边缘(遗留):
IE:
它有点丑(由于缩放),但它适用于大多数更新的浏览器:
input[type=checkbox] { /* Double-sized Checkboxes */ -ms-transform: scale(2); /* IE */ -moz-transform: scale(2); /* FF */ -webkit-transform: scale(2); /* Safari and Chrome */ -o-transform: scale(2); /* Opera */ transform: scale(2); padding: 10px; } /* Might want to wrap a span around your checkbox text */ .checkboxtext { /* Checkbox text */ font-size: 110%; display: inline; } <input type="checkbox" name="optiona" id="opta" checked /> <span class="checkboxtext"> Option A </span> <input type="checkbox" name="optionb" id="optb" /> <span class="checkboxtext"> Option B </span> <input type="checkbox" name="optionc" id="optc" /> <span class="checkboxtext"> Option C </span>
一个简单的解决方案是使用属性缩放:
输入[类型=“复选框”] { 变焦:1.5; } <输入类型=“复选框” />
我想做一个复选框,只是稍大一点,并查看37Signals Basecamp的源代码,以找到以下解决方案-
您可以更改字体大小,使复选框略大:
font-size: x-large;
然后,你可以正确对齐复选框,这样做:
vertical-align: top;
margin-top: 3px; /* change to center it */