2014-06-20 11 views
8

Provo a disegnare il colore di sfondo della casella di controllo, ma non cambierà tutto ciò che faccio. Sto usando Firefox 29 più recente.css - Perché non è possibile cambiare il colore della casella di controllo?

C'è qualche modifica alle regole in CSS o nel browser?

CSS:

input[type="checkbox"] { 
    background: #990000;  
} 

.chk { 
    background-color: #990000; 

} 

Ecco una demo http://jsfiddle.net/6KXRg/

+4

possibile duplicato di [Come stile casella di controllo utilizzando CSS?] (Http://stackoverflow.com/questions/4148499/how-to-style-checkbox-using-css) – blueygh2

+0

@ blueygh2 più simile a un duplicato perfetto, lol . – arielnmz

+0

grazie ragazzi ...!Ho già letto questo, voglio solo essere sicuro di quale sia il problema! – KeepMove

risposta

6

caselle di controllo non sono in grado di avere uno stile. Avresti bisogno di un plugin js di terze parti ce ne sono molti disponibili.

Se si vuole fare da soli, in pratica si tratta di nascondere la casella di controllo creando un elemento e uno stile come desiderato, quindi associare l'evento di clic a due funzioni una per cambiarne l'aspetto e un'altra per attivare l'evento click della casella di controllo.

Lo stesso problema si presenterà quando si tenta di definire la piccola freccia in giù su un elemento di selezione a discesa.

4

non potete modificare lo sfondo della casella di controllo, ma in qualche modo si può fare un trucco provare questo :)

.divBox { 
 
    width: 20px; 
 
    height: 20px; 
 
    background: #ddd; 
 
    margin: 20px 90px; 
 
    position: relative; 
 
    -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: 0px 1px 3px rgba(0,0,0,0.5); 
 
} 
 

 
.divBox label { 
 
    display: block; 
 
    width: 20px; 
 
    height: 20px; 
 
    -webkit-transition: all .5s ease; 
 
    -moz-transition: all .5s ease; 
 
    -o-transition: all .5s ease; 
 
    -ms-transition: all .5s ease; 
 
    transition: all .5s ease; 
 
    cursor: pointer; 
 
    position: absolute; 
 
    top: 1px; 
 
    z-index: 1; 
 
    /* 
 
    use this background transparent to check the value of checkbox 
 
    background: transparent; 
 
    */ 
 
    background: Black; 
 
    -webkit-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5); 
 
} 
 

 
.divBox input[type=checkbox]:checked + label { 
 
    background: green; 
 
}
<div class="divBox"> 
 
    <input type="checkbox" value="1" id="checkboxFourInput"name="" /> 
 
    <label for="checkboxFourInput"></label> 
 
</div>

22

Anche se la questione sia risolta ed è più vecchio, Nell'esplorare alcune opzioni per superare lo stile del problema delle caselle di controllo ho incontrato questo fantastico set di stili CSS3 solo per caselle di controllo e pulsanti radio che controllano i colori di sfondo e altri aspetti. Pensavo che questo potesse essere il vero problema di questa domanda.

JSFiddle

body { 
 
    background: #555; 
 
} 
 

 
h1 { 
 
    color: #eee; 
 
    font: 30px Arial, sans-serif; 
 
    -webkit-font-smoothing: antialiased; 
 
    text-shadow: 0px 1px black; 
 
    text-align: center; 
 
    margin-bottom: 50px; 
 
} 
 

 
input[type=checkbox] { 
 
    visibility: hidden; 
 
} 
 

 
/* SLIDE ONE */ 
 
.slideOne { 
 
    width: 50px; 
 
    height: 10px; 
 
    background: #333; 
 
    margin: 20px auto; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    position: relative; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
} 
 

 
.slideOne label { 
 
    display: block; 
 
    width: 16px; 
 
    height: 16px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 

 
    -webkit-transition: all .4s ease; 
 
    -moz-transition: all .4s ease; 
 
    -o-transition: all .4s ease; 
 
    -ms-transition: all .4s ease; 
 
    transition: all .4s ease; 
 
    cursor: pointer; 
 
    position: absolute; 
 
    top: -3px; 
 
    left: -3px; 
 

 
    -webkit-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    -moz-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
} 
 

 
.slideOne input[type=checkbox]:checked + label { 
 
    left: 37px; 
 
} 
 

 
/* SLIDE TWO */ 
 
.slideTwo { 
 
    width: 80px; 
 
    height: 30px; 
 
    background: #333; 
 
    margin: 20px auto; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    position: relative; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
} 
 

 
.slideTwo:after { 
 
    content: ''; 
 
    position: absolute; 
 
    top: 14px; 
 
    left: 14px; 
 
    height: 2px; 
 
    width: 52px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    background: #111; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
} 
 

 
.slideTwo label { 
 
    display: block; 
 
    width: 22px; 
 
    height: 22px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 

 
    -webkit-transition: all .4s ease; 
 
    -moz-transition: all .4s ease; 
 
    -o-transition: all .4s ease; 
 
    -ms-transition: all .4s ease; 
 
    transition: all .4s ease; 
 
    cursor: pointer; 
 
    position: absolute; 
 
    top: 4px; 
 
    z-index: 1; 
 
    left: 4px; 
 

 
    -webkit-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    -moz-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
} 
 

 
.slideTwo label:after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 10px; 
 
    height: 10px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    background: #333; 
 
    left: 6px; 
 
    top: 6px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,1), 0px 1px 0px rgba(255,255,255,0.9); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,1), 0px 1px 0px rgba(255,255,255,0.9); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,1), 0px 1px 0px rgba(255,255,255,0.9); 
 
} 
 

 
.slideTwo input[type=checkbox]:checked + label { 
 
    left: 54px; 
 
} 
 

 
.slideTwo input[type=checkbox]:checked + label:after { 
 
    background: #00bf00; 
 
} 
 

 
/* SLIDE THREE */ 
 
.slideThree { 
 
    width: 80px; 
 
    height: 26px; 
 
    background: #333; 
 
    margin: 20px auto; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    position: relative; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2); 
 
} 
 

 
.slideThree:after { 
 
    content: 'OFF'; 
 
    font: 12px/26px Arial, sans-serif; 
 
    color: #000; 
 
    position: absolute; 
 
    right: 10px; 
 
    z-index: 0; 
 
    font-weight: bold; 
 
    text-shadow: 1px 1px 0px rgba(255,255,255,.15); 
 
} 
 

 
.slideThree:before { 
 
    content: 'ON'; 
 
    font: 12px/26px Arial, sans-serif; 
 
    color: #00bf00; 
 
    position: absolute; 
 
    left: 10px; 
 
    z-index: 0; 
 
    font-weight: bold; 
 
} 
 

 
.slideThree label { 
 
    display: block; 
 
    width: 34px; 
 
    height: 20px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 

 
    -webkit-transition: all .4s ease; 
 
    -moz-transition: all .4s ease; 
 
    -o-transition: all .4s ease; 
 
    -ms-transition: all .4s ease; 
 
    transition: all .4s ease; 
 
    cursor: pointer; 
 
    position: absolute; 
 
    top: 3px; 
 
    left: 3px; 
 
    z-index: 1; 
 

 
    -webkit-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    -moz-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3); 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
} 
 

 
.slideThree input[type=checkbox]:checked + label { 
 
    left: 43px; 
 
} 
 

 
/* ROUNDED ONE */ 
 
.roundedOne { 
 
    width: 28px; 
 
    height: 28px; 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
    margin: 20px auto; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    position: relative; 
 
} 
 

 
.roundedOne label { 
 
    cursor: pointer; 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 20px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    left: 4px; 
 
    top: 4px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 

 
    background: -webkit-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -moz-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -o-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -ms-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: linear-gradient(top, #222 0%, #45484d 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#222', endColorstr='#45484d',GradientType=0); 
 
} 
 

 
.roundedOne label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
 
    filter: alpha(opacity=0); 
 
    opacity: 0; 
 
    content: ''; 
 
    position: absolute; 
 
    width: 16px; 
 
    height: 16px; 
 
    background: #00bf00; 
 

 
    background: -webkit-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: -moz-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: -o-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: -ms-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: linear-gradient(top, #00bf00 0%, #009400 100%); 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    top: 2px; 
 
    left: 2px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
} 
 

 
.roundedOne label:hover::after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; 
 
    filter: alpha(opacity=30); 
 
    opacity: 0.3; 
 
} 
 

 
.roundedOne input[type=checkbox]:checked + label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 
 
    filter: alpha(opacity=100); 
 
    opacity: 1; 
 
} 
 

 
/* ROUNDED TWO */ 
 
.roundedTwo { 
 
    width: 28px; 
 
    height: 28px; 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
    margin: 20px auto; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    position: relative; 
 
} 
 

 
.roundedTwo label { 
 
    cursor: pointer; 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 20px; 
 

 
    -webkit-border-radius: 50px; 
 
    -moz-border-radius: 50px; 
 
    border-radius: 50px; 
 
    left: 4px; 
 
    top: 4px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 

 
    background: -webkit-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -moz-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -o-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -ms-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: linear-gradient(top, #222 0%, #45484d 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#222', endColorstr='#45484d',GradientType=0); 
 
} 
 

 
.roundedTwo label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
 
    filter: alpha(opacity=0); 
 
    opacity: 0; 
 
    content: ''; 
 
    position: absolute; 
 
    width: 9px; 
 
    height: 5px; 
 
    background: transparent; 
 
    top: 5px; 
 
    left: 4px; 
 
    border: 3px solid #fcfff4; 
 
    border-top: none; 
 
    border-right: none; 
 

 
    -webkit-transform: rotate(-45deg); 
 
    -moz-transform: rotate(-45deg); 
 
    -o-transform: rotate(-45deg); 
 
    -ms-transform: rotate(-45deg); 
 
    transform: rotate(-45deg); 
 
} 
 

 
.roundedTwo label:hover::after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; 
 
    filter: alpha(opacity=30); 
 
    opacity: 0.3; 
 
} 
 

 
.roundedTwo input[type=checkbox]:checked + label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 
 
    filter: alpha(opacity=100); 
 
    opacity: 1; 
 
} 
 

 
/* SQUARED ONE */ 
 
.squaredOne { 
 
    width: 28px; 
 
    height: 28px; 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
    margin: 20px auto; 
 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    position: relative; 
 
} 
 

 
.squaredOne label { 
 
    cursor: pointer; 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 20px; 
 
    left: 4px; 
 
    top: 4px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 

 
    background: -webkit-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -moz-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -o-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -ms-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: linear-gradient(top, #222 0%, #45484d 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#222', endColorstr='#45484d',GradientType=0); 
 
} 
 

 
.squaredOne label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
 
    filter: alpha(opacity=0); 
 
    opacity: 0; 
 
    content: ''; 
 
    position: absolute; 
 
    width: 16px; 
 
    height: 16px; 
 
    background: #00bf00; 
 

 
    background: -webkit-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: -moz-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: -o-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: -ms-linear-gradient(top, #00bf00 0%, #009400 100%); 
 
    background: linear-gradient(top, #00bf00 0%, #009400 100%); 
 

 
    top: 2px; 
 
    left: 2px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
} 
 

 
.squaredOne label:hover::after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; 
 
    filter: alpha(opacity=30); 
 
    opacity: 0.3; 
 
} 
 

 
.squaredOne input[type=checkbox]:checked + label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 
 
    filter: alpha(opacity=100); 
 
    opacity: 1; 
 
} 
 

 
/* SQUARED TWO */ 
 
.squaredTwo { 
 
    width: 28px; 
 
    height: 28px; 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
    margin: 20px auto; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    position: relative; 
 
} 
 

 
.squaredTwo label { 
 
    cursor: pointer; 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 20px; 
 
    left: 4px; 
 
    top: 4px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1); 
 

 
    background: -webkit-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -moz-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -o-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -ms-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: linear-gradient(top, #222 0%, #45484d 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#222', endColorstr='#45484d',GradientType=0); 
 
} 
 

 
.squaredTwo label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
 
    filter: alpha(opacity=0); 
 
    opacity: 0; 
 
    content: ''; 
 
    position: absolute; 
 
    width: 9px; 
 
    height: 5px; 
 
    background: transparent; 
 
    top: 4px; 
 
    left: 4px; 
 
    border: 3px solid #fcfff4; 
 
    border-top: none; 
 
    border-right: none; 
 

 
    -webkit-transform: rotate(-45deg); 
 
    -moz-transform: rotate(-45deg); 
 
    -o-transform: rotate(-45deg); 
 
    -ms-transform: rotate(-45deg); 
 
    transform: rotate(-45deg); 
 
} 
 

 
.squaredTwo label:hover::after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; 
 
    filter: alpha(opacity=30); 
 
    opacity: 0.3; 
 
} 
 

 
.squaredTwo input[type=checkbox]:checked + label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 
 
    filter: alpha(opacity=100); 
 
    opacity: 1; 
 
} 
 

 

 
/* SQUARED THREE */ 
 
.squaredThree { 
 
    width: 20px;  
 
    margin: 20px auto; 
 
    position: relative; 
 
} 
 

 
.squaredThree label { 
 
    cursor: pointer; 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 20px; 
 
    top: 0; 
 
    border-radius: 4px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,.4); 
 
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,.4); 
 
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,.4); 
 

 
    background: -webkit-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -moz-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -o-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: -ms-linear-gradient(top, #222 0%, #45484d 100%); 
 
    background: linear-gradient(top, #222 0%, #45484d 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#222', endColorstr='#45484d',GradientType=0); 
 
} 
 

 
.squaredThree label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
 
    filter: alpha(opacity=0); 
 
    opacity: 0; 
 
    content: ''; 
 
    position: absolute; 
 
    width: 9px; 
 
    height: 5px; 
 
    background: transparent; 
 
    top: 4px; 
 
    left: 4px; 
 
    border: 3px solid #fcfff4; 
 
    border-top: none; 
 
    border-right: none; 
 

 
    -webkit-transform: rotate(-45deg); 
 
    -moz-transform: rotate(-45deg); 
 
    -o-transform: rotate(-45deg); 
 
    -ms-transform: rotate(-45deg); 
 
    transform: rotate(-45deg); 
 
} 
 

 
.squaredThree label:hover::after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; 
 
    filter: alpha(opacity=30); 
 
    opacity: 0.3; 
 
} 
 

 
.squaredThree input[type=checkbox]:checked + label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 
 
    filter: alpha(opacity=100); 
 
    opacity: 1; 
 
} 
 

 
/* SQUARED FOUR */ 
 
.squaredFour { 
 
    width: 20px;  
 
    margin: 20px auto; 
 
    position: relative; 
 
} 
 

 
.squaredFour label { 
 
    cursor: pointer; 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 20px; 
 
    top: 0; 
 
    border-radius: 4px; 
 

 
    -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5); 
 
    background: #fcfff4; 
 

 
    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0); 
 
} 
 

 
.squaredFour label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
 
    filter: alpha(opacity=0); 
 
    opacity: 0; 
 
    content: ''; 
 
    position: absolute; 
 
    width: 9px; 
 
    height: 5px; 
 
    background: transparent; 
 
    top: 4px; 
 
    left: 4px; 
 
    border: 3px solid #333; 
 
    border-top: none; 
 
    border-right: none; 
 

 
    -webkit-transform: rotate(-45deg); 
 
    -moz-transform: rotate(-45deg); 
 
    -o-transform: rotate(-45deg); 
 
    -ms-transform: rotate(-45deg); 
 
    transform: rotate(-45deg); 
 
} 
 

 
.squaredFour label:hover::after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; 
 
    filter: alpha(opacity=30); 
 
    opacity: 0.5; 
 
} 
 

 
.squaredFour input[type=checkbox]:checked + label:after { 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 
 
    filter: alpha(opacity=100); 
 
    opacity: 1; 
 
}
<h1>CSS3 Checkbox Styles</h1> 
 

 
<!-- Slide ONE --> 
 
<div class="slideOne"> 
 
    <input type="checkbox" value="None" id="slideOne" name="check" /> 
 
    <label for="slideOne"></label> 
 
</div> 
 

 
<!-- Slide TWO --> 
 
<div class="slideTwo"> 
 
    <input type="checkbox" value="None" id="slideTwo" name="check" /> 
 
    <label for="slideTwo"></label> 
 
</div> 
 

 
<!-- Slide THREE --> 
 
<div class="slideThree">  
 
    <input type="checkbox" value="None" id="slideThree" name="check" /> 
 
    <label for="slideThree"></label> 
 
</div> 
 

 
<!-- Rounded ONE --> 
 
<div class="roundedOne"> 
 
    <input type="checkbox" value="None" id="roundedOne" name="check" /> 
 
    <label for="roundedOne"></label> 
 
</div> 
 

 
<!-- Rounded TWO --> 
 
<div class="roundedTwo"> 
 
    <input type="checkbox" value="None" id="roundedTwo" name="check" /> 
 
    <label for="roundedTwo"></label> 
 
</div> 
 

 
<!-- Squared ONE --> 
 
<div class="squaredOne"> 
 
    <input type="checkbox" value="None" id="squaredOne" name="check" /> 
 
    <label for="squaredOne"></label> 
 
</div> 
 

 
<!-- Squared TWO --> 
 
<div class="squaredTwo"> 
 
    <input type="checkbox" value="None" id="squaredTwo" name="check" /> 
 
    <label for="squaredTwo"></label> 
 
</div> 
 

 
<!-- Squared THREE --> 
 
<div class="squaredThree"> 
 
    <input type="checkbox" value="None" id="squaredThree" name="check" /> 
 
    <label for="squaredThree"></label> 
 
</div> 
 

 
<!-- Squared FOUR --> 
 
<div class="squaredFour"> 
 
    <input type="checkbox" value="None" id="squaredFour" name="check" /> 
 
    <label for="squaredFour"></label> 
 
</div>

+4

Questi sono fantastici, ma è stato un dolore reale cercando di ottenere il testo di lato della casella di controllo. Mi sto quasi arrendendo. – HerrimanCoder

+0

Wow è super bello. –

+0

È davvero fantastico! Grazie! :) +1 –

5

Tecnicamente, è possibile cambiare il colore di qualsiasi cosa con i CSS. Come accennato, non è possibile modificare il colore di sfondo o il colore, ma è possibile utilizzare i filtri CSS. Per esempio:

input[type="checkbox"] { /* change "blue" browser chrome to yellow */ 
    filter: invert(100%) hue-rotate(18deg) brightness(1.7); 
} 

Se siete veramente alla ricerca di controllo della progettazione su caselle di controllo, però, la cosa migliore è fare la casella di controllo "nascosto" e lo stile di un elemento adiacente, ad esempio un div.

+0

Eccellente, semplice. –

1

Trasparenza forse: casella di controllo all'interno lasso

<span style="display:inline-block; background-color:silver;padding:0px;margin:0px;height:13px; width:13px; overflow:hidden"><input type="checkbox" style="opacity:0.50;padding:0px;margin:0px" /></span> 
6

ho avuto lo stesso problema, cercando di utilizzare grandi ingressi e aveva una piccola casella di controllo. Dopo alcune ricerche, questo è abbastanza buono per le mie esigenze:

input[type='checkbox']{ 
    width: 30px !important; 
    height: 30px !important; 
    margin: 5px; 
    -webkit-appearance: none; 
    -moz-appearance: none; 
    -o-appearance: none; 
    appearance:none; 
    outline: 2px solid lightblue; 
    box-shadow: none; 
    font-size: 2em; 
} 

JSFiddle

Forse qualcuno lo troverà utile.

+0

grazie .. mi ha aiutato molto – Wanderer