网页中的复选框 - 如何使它们更大?

Ton*_*ony 103 html css checkbox

在大多数浏览器中呈现的标准复选框非常小,即使使用较大的字体也不会增加大小.什么是最好的,独立于浏览器的方式来显示更大的复选框?

小智 129

如果这可以帮助任何人,这里的简单CSS作为一个跳跃点.将它变成一个基本的圆角正方形,足够大的拇指与切换的背景颜色.

input[type='checkbox'] {
    -webkit-appearance:none;
    width:30px;
    height:30px;
    background:white;
    border-radius:5px;
    border:2px solid #555;
}
input[type='checkbox']:checked {
    background: #abd;
}
Run Code Online (Sandbox Code Playgroud)
<input type="checkbox" />
Run Code Online (Sandbox Code Playgroud)

  • 如果里面也有一个勾号会很好:) (11认同)
  • 很好 - 但仅限Chorme/Safari - 对吗? (2认同)

Flo*_*anB 43

实际上有一种方法可以让它们更大,复选框就像其他任何东西一样(甚至像facebook按钮那样的iframe).

将它们包裹在"缩放"元素中:

.double {
  zoom: 2;
  transform: scale(2);
  -ms-transform: scale(2);
  -webkit-transform: scale(2);
  -o-transform: scale(2);
  -moz-transform: scale(2);
  transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  -webkit-transform-origin: 0 0;
  -o-transform-origin: 0 0;
  -moz-transform-origin: 0 0;
}
Run Code Online (Sandbox Code Playgroud)
<div class="double">
  <input type="checkbox" name="hello" value="1">
</div>
Run Code Online (Sandbox Code Playgroud)

它可能看起来有点"重新调整",但它的工作原理.

当然你可以让div浮动:离开并放置你的标签,浮动:左边.

  • 请注意,在 Firefox 上(从版本 36 开始),这将导致外观非常模糊。不过,它在 Chrome 中可以很好地扩展。演示:http://jsfiddle.net/tzp858j3/ (3认同)
  • 不能将“ zoom:2”和“ transform:scale(2)”直接应用于复选框吗?为什么需要包装纸? (2认同)

Col*_*ite 26

试试这个CSS

input[type=checkbox] {width:100px; height:100px;}
Run Code Online (Sandbox Code Playgroud)

  • 这只适用于某些浏览器,而不适用于许多现代浏览器. (6认同)
  • 主要的限制是它在Firefox中根本不起作用(从Firefox 36开始)并且实际上看起来非常不自然(复选框是常规大小的,但是它周围的填充填充了100 x 100px区域. (3认同)
  • 不是完全跨浏览器(最好在HTML中设置类并在CSS中使用类选择器),但这可能是比我更好的解决方案.+1 (2认同)

Jus*_*tin 16

我尝试改变paddingand 和marginand 以及widthand height,然后终于发现如果你只是增加比例它会起作用:

input[type=checkbox] {
    transform: scale(1.5);
}
Run Code Online (Sandbox Code Playgroud)


Fla*_*orm 7

仅纯现代 2020 CSS决定,没有模糊缩放或不方便的转换。并带有勾号!=)

\n

在 Firefox 和基于 Chromium 的浏览器中运行良好。

\n

因此,您可以纯粹通过设置父块来规则您的复选框ADAPTIVEfont-size,它会随着文本而增长!

\n

\r\n
\r\n
input[type=\'checkbox\'] {\n  -moz-appearance: none;\n  -webkit-appearance: none;\n  appearance: none;\n  vertical-align: middle;\n  outline: none;\n  font-size: inherit;\n  cursor: pointer;\n  width: 1.0em;\n  height: 1.0em;\n  background: white;\n  border-radius: 0.25em;\n  border: 0.125em solid #555;\n  position: relative;\n}\n\ninput[type=\'checkbox\']:checked {\n  background: #adf;\n}\n\ninput[type=\'checkbox\']:checked:after {\n  content: "\xe2\x9c\x94";\n  position: absolute;\n  font-size: 90%;\n  left: 0.0625em;\n  top: -0.25em;\n}
Run Code Online (Sandbox Code Playgroud)\r\n
<label for="check1"><input type="checkbox" id="check1" checked="checked" /> checkbox one</label>\n<label for="check2"><input type="checkbox" id="check2" /> another checkbox</label>\n<label for="check3" style="font-size:150%"><input type="checkbox" id="check3" checked="checked" /> bigger checkbox </label>
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n