We all know the general situation. Using CSS to define the radio single option and CheckBox check box style is not valid, let me introduce you to the use of CSS definition radio single option and CheckBox check box style, there is need to know the friend can refer to.
Use CSS to fully instantiate
Copy CodeThe code is as follows: <style type= "Text/css" >
Form#form1 {font:12px Tahoma,sans-serif}
Input[type= "checkbox"] {visibility:hidden;width:0;height:0;margin:0;padding:0;}
input[type= "checkbox"]+label {background:url (checkstyle.gif) No-repeat;padding-left:18px;color: #ccc;}
input[type= "checkbox"]+label:hover {color: #369; background-position:0 -16px;}
input[type= "checkbox"]:checked+label {color: #000; background-position:0 -48px;}
input[type= "checkbox"]:focus+label {color: #963; background-position:0 -32px;}
Input[type= "Radio"] {visibility:hidden;width:0;height:0;margin:0;padding:0;}
Input[type= "Radio"]+label {background:url (checkstyle.gif) no-repeat 0-64px;padding-left:18px;color: #ccc;}
Input[type= "Radio"]+label:hover {color: #369; background-position:0 -80px;}
Input[type= "Radio"]:checked+label {color: #000; background-position:0 -112px;}
Input[type= "Radio"]:focus+label {color: #963; background-position:0 -96px;}
</style> using JS to instance
HTML codeCopy CodeThe code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8″>
<link rel= "stylesheet" href= "Css/screensmall.css" type= "text/css" media= "screen" >
<body bgcolor= #000000 >
<div class= ' section demo ' >
<form action= "onsubmit= ' void (0) ' >
<div>
<label><input type= "checkbox" checked= "checked" > I ' m a fancy cross-browser styled checkbox</label>
<div class= ' Leftcol ' >
<label><input type= "checkbox" > This is a checkbox</label>
<label><input type= "checkbox" checked= "Checked" > this is a checkbox</label>
<label><input type= "checkbox" > This is a checkbox</label>
</div>
<div class= ' Rightcol ' >
<label><input type= "checkbox" checked= "Checked" > this is a checkbox</label>
<label><input type= "checkbox" > This is a checkbox</label>
<label><input type= "checkbox" checked= "Checked" > this is a checkbox</label>
</div>
<label><input type= "checkbox" checked= "checked" > Apply any CSS styles for different states</label>
</div>
<div class= ' Leftcol ' >
<label><input type= "Radio" Name= ' Leftcol ' > This is a radio button</label>
<label><input type= "Radio" checked= "checked" name= ' Leftcol ' > This is a radio button</label>
<label><input type= "Radio" Name= ' Leftcol ' > This is a radio button</label>
</div>
<div class= ' Rightcol ' >
<label><input type= "Radio" Name= ' Rightcol ' > This is a radio button</label>
<label><input type= "Radio" checked= "checked" name= ' Rightcol ' > This is a radio button</label>
<label><input type= "Radio" Name= ' Rightcol ' > This is a radio button</label>
</div>
<input type= "reset" value= "reset Form" style= ' margin:1em;height:2.5em;background: #222; Float:right;color: #fff ' >
</form>
</div>
<script type= "Text/javascript" src= "Js/mootools.js" ></script>
<script type= "Text/javascript" src= "Js/moocheck.js" ></script>
</body>
Start:function (elements, options) {
fancyform.initing = 1;
if ($type (elements)! = ' array ') elements = $$ (' input ');
if (!options) options = [];
Fancyform.onclasses = ($type (options[' onclasses ') = = = ' object ')? options[' onclasses ']: {
CheckBox: ' Checked ',
Radio: ' Selected '
}
Fancyform.offclasses = ($type (options[' offclasses ') = = = ' object ')? options[' offclasses ']: {
CheckBox: ' Unchecked ',
Radio: ' Unselected '
}
if ($type (options[' extraclasses ') = = = ' object ') {
Fancyform.extra = options[' extraclasses '];
} else if (options[' extraclasses ']) {
Fancyform.extra = {
CheckBox: ' F_checkbox ',
Radio: ' F_radio ',
On: ' f_on ',
Off: ' F_off ',
All: ' Fancy '}
} else {
Fancyform.extra = {};
}
Fancyform.onselect = $pick (options[' onSelect '), function (EL) {});
Fancyform.ondeselect = $pick (options[' ondeselect '), function (EL) {});
var keeps = [];
FANCYFORM.CHKS = Elements.filter (function (CHK) {
if ($type (chk)! = ' element ') return false;
if (chk.get (' tag ') = = ' input ' && (fancyform.onclasses[chk.getproperty (' type ')])) {
var el = chk.getparent ();
if (el.getelement (' input ') ==chk) {
El.type = Chk.getproperty (' type ');
El.inputelement = chk;
This.push (EL);
} else {
Chk.addevent (' click ', function (f) {
if (f.event.stoppropagation) f.event.stoppropagation ();
});
}
} else if ((chk.inputelement = chk.getelement (' input ')) && (fancyform.onclasses[(Chk.type = Chk.inputElement.getProperty (' type '))]) {
return true;}
return false;
}.bind (keeps));
FANCYFORM.CHKS = FancyForm.chks.combine (keeps);
keeps = null;
FancyForm.chks.each (function (CHK) {
var c = chk.inputelement;
C.setstyle (' position ', ' absolute ');
C.setstyle (' left ', ' -9999px ');
Chk.addevent (' Selectstart ', function (f) {f.stop ()});
Chk.name = C.getproperty (' name ');
Fancyform.update (CHK);
});
FancyForm.chks.each (function (CHK) {
var c = chk.inputelement;
Chk.addevent (' click ', function (f) {
F.stop (); F.type = ' prop ';
C.fireevent (' Click ', F, 1);
});
Chk.addevent (' MouseDown ', function (f) {
if ($type (c.onmousedown) = = ' function ')
C.onmousedown ();
F.preventdefault ();
});
Chk.addevent (' MouseUp ', function (f) {if ($type (c.onmouseup) = = ' function ')
C.onmouseup ();
});
C.addevent (' Focus ', function (f) {
if (Fancyform.focus)
Chk.setstyle (' outline ', ' 1px dotted ');
});
C.addevent (' Blur ', function (f) {
Chk.setstyle (' outline ', 0);
});
C.addevent (' click ', function (f) {
if (f.event.stoppropagation) f.event.stoppropagation ();
if (C.getproperty (' disabled '))//C.getstyle (' position ')! = ' absolute '
Return
if (!chk.hasclass (Fancyform.onclasses[chk.type]))
C.setproperty (' checked ', ' checked ');
else if (chk.type! = ' Radio ')
C.setproperty (' checked ', false);
if (F.type = = ' prop ')
Fancyform.focus = 0;
Fancyform.update (CHK);
Fancyform.focus = 1;
if (F.type = = ' prop ' &&! Fancyform.initing && $type (c.onclick) = = ' function ')
C.onclick ();
});
C.addevent (' MouseUp ', function (f) {if (f.event.stoppropagation) f.event.stoppropagation ();
});
C.addevent (' MouseDown ', function (f) {
if (f.event.stoppropagation) f.event.stoppropagation ();
});
if (Extraclass = Fancyform.extra[chk.type])
Chk.addclass (Extraclass);
if (Extraclass = fancyform.extra[' All ')
Chk.addclass (Extraclass);
});
fancyform.initing = 0;
$each ($$ (' form '), function (x) {
X.addevent (' Reset ', function (a) {
Window.settimeout (function () {FancyForm.chks.each (function (x) {fancyform.update (x); X.inputelement.blur ()})}, 200) ;
});
});
},
Update:function (CHK) {
if (Chk.inputElement.getProperty (' checked ')) {
Chk.removeclass (Fancyform.offclasses[chk.type]);
Chk.addclass (Fancyform.onclasses[chk.type]);
if (Chk.type = = ' Radio ') {
FancyForm.chks.each (function (other) {
if (Other.name = = Chk.name && Other! = chk) {
Other.inputElement.setProperty (' checked ', false); Fancyform.update (other);
}
});
}
if (Extraclass = fancyform.extra[' on ')
Chk.addclass (Extraclass);
if (Extraclass = fancyform.extra[' off ')
Chk.removeclass (Extraclass);
if (! fancyform.initing)
Fancyform.onselect (CHK);
} else {
Chk.removeclass (Fancyform.onclasses[chk.type]);
Chk.addclass (Fancyform.offclasses[chk.type]);
if (Extraclass = fancyform.extra[' off ')
Chk.addclass (Extraclass);
if (Extraclass = fancyform.extra[' on ')
Chk.removeclass (Extraclass);
if (! fancyform.initing)
Fancyform.ondeselect (CHK);
}
if (! fancyform.initing)
Chk.inputElement.focus ();
},
All:function () {
FancyForm.chks.each (function (CHK) {
Chk.inputElement.setProperty (' checked ', ' checked '); Fancyform.update (CHK);
});
},
None:function () {
FancyForm.chks.each (function (CHK) {
Chk.inputElement.setProperty (' checked ', false);
Fancyform.update (CHK);
});
}
};
Window.addevent (' Domready ', function () {
Fancyform.start ();
});
CSS definition radio single option and checkbox check box style valid code