我正在尝试创建一个用户可以选择选项的表单,而不是使用复选框,我希望他们能够选择图像。
当他们选择图像时,他们可能会在他们周围有一个边框,表明他们已被选中。
哪种输入处理这个?
答案 0 :(得分:2)
由于复选框是选中/未选中的默认HTML行为,我会这样做:
这将具有额外的优势,即禁用Javascript的人仍然可以通过单击复选框来选择图像。
答案 1 :(得分:0)
使用buttons。您可以使用用户将看到的背景图像,并使用元素的值处理表单。
再见
答案 2 :(得分:0)
您可以使用jQuery插件http://ajaxdump.com/?0BNm4jJ0
答案 3 :(得分:0)
您可以反过来使用(仅在Chrome中测试):before
和图片:
演示:http://jsfiddle.net/SO_AMK/hG9Fh/
不,我做了不只是输入我头顶的所有CSS :D
CSS,此代码纯粹是为Chrome构建的,并且不以任何方式跨浏览器兼容:
input[type='checkbox'] {
-webkit-appearance: none;
-webkit-user-select: none;
background-image: -webkit-linear-gradient(#ededed, #ededed 38%, #dedede);
border: 1px solid rgba(0, 0, 0, 0.25);
border-radius: 2px;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08),
inset 0 1px 2px rgba(255, 255, 255, 0.75);
color: #444;
font: inherit;
margin: 0 1px 0 0;
text-shadow: 0 1px 0 rgb(240, 240, 240);
}
input[type='checkbox'] {
bottom: 2px;
height: 13px;
position: relative;
vertical-align: middle;
width: 13px;
}
input[type='checkbox']:checked::before {
-webkit-user-select: none;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8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SRAeC0Sux3dfSCTetE0wKyXxOWhMKhTYIr9CAUXyJMzgLgBagBBgDPGAI2LGdNt0T1AAAAAAElFTkSuQmCC');
background-size: 100% 100%;
content: '';
display: block;
height: 100%;
width: 100%;
}
:enabled:hover:input[type='checkbox'] {
background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
border-color: rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12),
inset 0 1px 2px rgba(255, 255, 255, 0.95);
color: black;
}
:enabled:active:input[type='checkbox'] {
background-image: -webkit-linear-gradient(#e7e7e7, #e7e7e7 38%, #d7d7d7);
box-shadow: none;
text-shadow: none;
}
input:disabled:[type='checkbox'] {
opacity: .75;
}
:enabled:focus:input[type='checkbox'] {
-webkit-transition: border-color 200ms;
border-color: rgb(77, 144, 254);
outline: none;
}
将复选框替换为触发它们的图片,点击此处有一篇好文章:http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/