Jef*_*f B 31
我创建了一个透明的png,外面是白色的,复选框是部分透明的.我修改了代码,在元素上放了一个backgroundColor,然后是一个彩色复选框.
http://i48.tinypic.com/raz13m.jpg(它说jpg,但它是一个png).
我会发布这个例子,但我不知道一个很好的方式来展示它.那里有什么好的沙箱网站?
当然,这取决于png支持.你可能用gif很难做到这一点,或者像你建议的那样在图像上放一个半透明的css层,然后使用gif蒙版来掩盖彩色盒子的出血.此方法假定透明度支持.
我的png方法使用您链接到的页面中的css,js,并进行以下更改:
JS:
// Changed all instances of '== "styled"' to '.search(...)'
// to handle the additional classes needed for the colors (see CSS/HTML below)
if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className.search(/^styled/) != -1) {
span[a] = document.createElement("span");
// Added '+ ...' to this line to handle additional classes on the checkbox
span[a].className = inputs[a].type + inputs[a].className.replace(/^styled/, "");
Run Code Online (Sandbox Code Playgroud)
CSS:
.checkbox, .radio {
width: 19px;
height: 25px;
padding: 0px; /* Removed padding to eliminate color bleeding around image
you could make the image wider on the right to get the padding back */
background: url(checkbox2.png) no-repeat;
display: block;
clear: left;
float: left;
}
.green {
background-color: green;
}
.red {
background-color: red;
}
etc...
Run Code Online (Sandbox Code Playgroud)
HTML:
<p><input type="checkbox" name="1" class="styled green"/> (green)</p>
<p><input type="checkbox" name="2" class="styled red" /> (red)</p>
<p><input type="checkbox" name="3" class="styled purple" /> (purple)</p>
Run Code Online (Sandbox Code Playgroud)
希望有道理.
编辑:
这是一个jQuery示例,说明了复选框的原理:
http://jsfiddle.net/jtbowden/xP2Ns/
听起来你已经知道了这一点,但是你上面链接的解决方案实际上用带有图像的span标签替换了复选框,以提供"样式化"复选框的效果.
对于大多数浏览器,如IE和Firefox,几乎没有(如果有的话)选项,只有CSS的样式复选框支持很少.
归档时间: |
|
查看次数: |
86057 次 |
最近记录: |