I wanna change color for each checkbox while hover.I have four checkbox.I wanna change the color, If I hover the 'all' checkbox it shows red,blue color for 'cold',orange for 'warm' and green for 'Active'.
#ck-button {
margin: 0px;
background-color: #EFEFEF;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
float: left;
}
#ck-button label {
float: left;
width: 4.0em;
}
#ck-button label span {
text-align: center;
padding: 3px 0px;
display: block;
border-radius: 4px;
}
#ck-button label input {
position: absolute;
top: -20px;
}
input:checked +span {
background-color: #911;
color: #fff;
}
#ck-button input:hover #all + span {
background-color: #efE0E0;
}
#ck-button input:hover #o1 + span {
background-color: blue;
}
#ck-button input:hover #o2 + span {
background-color: orange;
}
#ck-button input:hover #o3 + span {
background-color: green;
}
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id=all value="All" checked><span>All</span>
</label>
</div>
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id="o1" value="Cold" onclick=handleClick1(this.val);><span class="o1">Cold</span>
</label>
</div>
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id="o2" value="Warm" onclick="handleClick1(this.val);"><span>Warm</span>
</label>
</div>
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id="o3" value="Active" onclick="handleClick1(this.val);"><span>Active</span>
</label>
</div>
In the last four lines use label:hover instead of input:hover. Input is positioned to top and isn't hovered (is outside the label).
#ck-button label:hover #all + span {
background-color:#efE0E0;
}
#ck-button label:hover #o1 + span {
background-color:blue;
}
#ck-button label:hover #o2 + span {
background-color:orange;
}
#ck-button label:hover #o3 + span {
background-color:green;
}
http://jsfiddle.net/3q4uuvum/3/
even as an option
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
ul{
text-align: center;
width: 300px;
margin: 25px auto;
}
ul > li{
display: inline-block;
*display: inline;
zoom: 1;
vertical-align: top;
width: 100px;
height: 100px;
border: 1px solid #ccc;
position: relative;
}
input{
display: none;
}
label{
display: block;
width: 100px;
height: 100px;
}
label:hover{
background: #f7f7f7;
}
input:checked ~ label{
position: absolute; top: 0; left: 0;
width: 100%;
height: 100%;
background: url(http://html5doctor.com/wp-content/themes/html5doctor2/images/HTML5_Badge_64.png) no-repeat center center;
border: 1px solid #000;
}
<ul>
<li>
<input type="checkbox" id="c1" name="checkbox" />
<label for="c1"></label>
<li>
<input type="checkbox" id="c2" name="checkbox" />
<label for="c2"></label>
<li>
<input type="checkbox" id="c3" name="checkbox" />
<label for="c3"></label>
<li>
<input type="checkbox" id="c4" name="checkbox" checked />
<label for="c4"></label>
<li>
<input type="checkbox" id="c5" name="checkbox" />
<label for="c5"></label>
<li>
<input type="checkbox" id="c6" name="checkbox" />
<label for="c6"></label>
<li>
<input type="checkbox" id="c7" name="checkbox" />
<label for="c7"></label>
<li>
<input type="checkbox" id="c8" name="checkbox" />
<label for="c8"></label>
<li>
<input type="checkbox" id="c9" name="checkbox" />
<label for="c9"></label>
</ul>
I couldn't find online how to display different colors for hover depending if the box is checked, but after tirelessly tweaking the code I figured it out.
.ck-button-class:hover input:checked + span {
background-color: green;
}
This is assuming you assigned the class to these buttons, <div id="ck-button" class="ck-button-class">.
Related
I have a question:
I want my radio button at default-mode to have the css:
border-color: #00AD51;
color: #fff;
background-color: #00AD51;
and when the user selects/clicks on another radio button it changes to this css:
border-color: #00AD51;
color: #00AD51;
background-color: #fff;
Is this possible? How can I make specific css on default-mode and checked-mode on radio buttons?
HTML:
<p><b>What is your favorite animal?</b></p><br />
<div class="Animals"><div class="input">
<input id="dog" type="radio" name="Animal" checked>
<label for="dog"><span>Dog</span></label>
</div>
<div class="Animals"><div class="input">
<input id="cat" type="radio" name="Animal">
<label for="cat"><span>Cat</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Horse" type="radio" name="Animal">
<label for="Horse"><span>Horse</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Cow" type="radio" name="Animal">
<label for="Cow"><span>Cow</span></label>
</div>
Link to codepen: https://codepen.io/vicm/pen/QBPQWZ
Here is a snippet where I:
Added the closing </div> in your HTML,
Reorganized your CSS code and tried to remove duplicate styled properties,
Corrected some typo errors (display: inline-blok to display: inline-block, position:relavitve; to position: relative; …),
I added some styling plus comments to make things clear about the different possible states,
Instead of using checked on the "recommended" answer, you can use another custom property, like "recommend", and use it in your CSS to stylize it correctly.
input[type=radio] {
margin-right: 3px;
position: relative;
top: 3px;
}
.Animals {
display: inline-block;
height: 100px;
margin: 10px;
border: 2px solid #003D6A;
border-radius: 3px;
background-color: #fff;
padding: 10px;
text-align: center;
line-height: 20px;
font-family: Helvetica;
font-size: 20px;
}
.Animals .input {
padding-bottom: 0;
}
.Animals input[type=radio] {
opacity: 0;
}
.Animals input[type=radio]+label {
cursor: pointer;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0);
border: 2px solid;
margin: 10px;
height: 100px;
border-radius: 3px;
text-align: center;
font-size: 20px;
font-family: Helvetica;
width: 292px;
/* Default */
border-color: darkblue;
background-color: #fff;
color: darkblue;
}
/* Recommanded */
.Animals input[type=radio][recommand]+label {
border-color: turquoise;
color: turquoise;
}
/* Hover */
.Animals input[type=radio]+label:hover {
border-color: #00AD51;
color: #00AD51;
}
/* Checked */
.Animals input[type=radio]:checked+label {
border-color: #00AD51;
background-color: #00AD51;
color: #fff;
}
.Animals label span {
position: relative;
top: 33%;
}
<p><b>What is your favorite animal?</b></p><br />
<div class="Animals">
<div class="input">
<input id="dog" type="radio" name="Animal" recommand>
<label for="dog"><span>Dog</span></label>
</div>
</div>
<div class="Animals">
<div class="input">
<input id="cat" type="radio" name="Animal">
<label for="cat"><span>Cat</span></label>
</div>
</div>
<div class="Animals">
<div class="input">
<input id="Horse" type="radio" name="Animal">
<label for="Horse"><span>Horse</span></label>
</div>
</div>
<div class="Animals">
<div class="input">
<input id="Cow" type="radio" name="Animal">
<label for="Cow"><span>Cow</span></label>
</div>
</div>
If you wish to modify something, it should be easier now.
You can use this simple trick.
When user can click or check the radio button
.Animals input[type=radio]:checked + label{border-color: #00AD51;color: #00AD51;background-color: #fff;}
Hope this help.
Let me know further clarification.
input[type=radio]
{
margin-right: 3px;
position: relative;
top: 3px;
}
.Animals
{
border:2px solid #003D6A;
margin:10px;
height:100px;
padding:10px;
border-radius:3px;
text-align:center;
font-size: 20px;
line-height: 20px;
background-color:#fff;
font-family: Helvetica;
display: inline-blok;
}
.Animals{
margin: 0 auto;
}
.Animals input[type=radio] {
opacity: 0;
position:relavitve;
}
.Animals input[type=radio] + label {
cursor: pointer;
text-shadow: 1px 1px 0 rgba(0,0,0,0);
border: 2px solid #003D6A;
margin: 10px;
height: 100px;
border-radius: 3px;
text-align: center;
font-size: 20px;
font-family: Helvetica;
width: 292px;
background-color: #ffffff;
}
.Animals input[type=radio] + label:hover{
border-color: #00AD51;
background-color: #fff;
color: #00AD51;
}
.Animals .input
{
padding-bottom:0;
}
.Animals label span
{
position:relative;
top:33%;
}
.Animals input[type=radio]:checked + label{
border-color: #00AD51;
color: #00AD51;
background-color: #fff;
}
<p><b>What is your favorite animal?</b></p><br />
<div class="Animals"><div class="input">
<input id="dog" type="radio" name="Animal" checked>
<label for="dog"><span>Dog</span></label>
</div>
<div class="Animals"><div class="input">
<input id="cat" type="radio" name="Animal">
<label for="cat"><span>Cat</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Horse" type="radio" name="Animal">
<label for="Horse"><span>Horse</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Cow" type="radio" name="Animal">
<label for="Cow"><span>Cow</span></label>
</div>
Here I made two simple input fields, but when I zoom in and zoom out on the page (Ctrl + Mouse wheel) somehow the input fields change places, input goes down and up, why it is doing this? How to have them at the same place whether I zoom in or out?
body {
width: 870px;
}
#col3 {
width: 400px;
float: left;
/*background-color:#383838;*/
margin: 20px 10px 10px 30px;
}
form {
width: 380px;
margin: auto;
padding: 5px;
border: solid 1px white;
}
fieldset {
margin: auto;
border: solid 1px #E37222;
padding-left: 19px;
padding-top: 15px;
background-color: #EEEEDD;
}
label {
display: block;
width: 70px;
float: left;
margin-left: 10px;
}
span {
margin-left: -16px;
}
legend {
background-color: #E37222;
color: white;
}
input.tt {
outline: 1px solid #909090;
}
.tt {
margin-top: 8px;
}
<div id="col3">
<form>
<fieldset>
<legend>eeeee</legend>
<label for="name">
<span>rrr:</span>
</label>
<input class="tt" type="text" size="34" />
<br />
<label class="tt" for="email">
<span>ttt:</span>
</label>
<input class="tt" type="text" size="34" />
</fieldset>
</form>
</div>
..........................
Remove float:left for <label>
label{
display:block;
width:70px;
margin-left:10px;
}
Try with This
.youclassname{
display:flex;
}
<div class="yourclassname">
<label for="name"><span>rrrrrr rrrrrr:</span></label>
<input class="tt type="text" size="34" />
</div>
Either change your markup a little like that, or use flexbox/grid.
<style>
body{
width:870px;
}
#col3{
width:400px;
float:left;
/*background-color:#383838;*/
margin:20px 10px 10px 30px;
}
form{
width:380px;
margin:auto;
padding:5px;
border:solid 1px white;
}
fieldset{
margin:auto;
border:solid 1px #E37222;
padding-left: 19px;
padding-top: 15px;
background-color: #EEEEDD;
}
label{
display:block;
width: 100%;
}
label div{
padding-right: 5px;
width: 68px;
display: inline-block;
}
legend{
background-color:#E37222;
color:white;
}
input.tt{
outline: 1px solid #909090;
}
.tt{
margin-top:8px;
}
</style>
</head>
<body>
<div id="col3">
<form ">
<fieldset >
<legend>eeeee</legend>
<label for="name"><div>rrr:</div><input class="tt type="text" size="34" /> </label>
<br/>
<label class="tt"for="email"><div>ttt:</div><input class="tt" type="text" size="34" /></label>
</fieldset>
</form>
</div>
</body>
I am trying to put a letter inside a radio button (with Materialize framework) like the A and B in this image.
How do I do this?
Here is the customize radio button.
see the comments given in css.
input[type="radio"] {
width: 30px;
height: 30px;
border-radius: 15px;
border: 2px solid #1FBED6;
background-color: white;
-webkit-appearance: none; /*to disable the default appearance of radio button*/
-moz-appearance: none;
}
input[type="radio"]:focus { /*no need, if you don't disable default appearance*/
outline: none; /*to remove the square border on focus*/
}
input[type="radio"]:checked { /*no need, if you don't disable default appearance*/
background-color: #1FBED6;
}
input[type="radio"]:checked ~ span:first-of-type {
color: white;
}
label span:first-of-type {
position: relative;
left: -27px;
font-size: 15px;
color: #1FBED6;
}
label span {
position: relative;
top: -12px;
}
<label>
<input type="radio" name="options"/>
<span>A</span><span>Option A</span>
</label>
<br/>
<label>
<input type="radio" name="options"/>
<span>B</span><span>Option B</span>
</label>
<br/>
<label>
<input type="radio" name="options"/>
<span>C</span><span>Option C</span>
</label>
<br/>
<label>
<input type="radio" name="options"/>
<span>D</span><span>Option D</span>
</label>
You cannot do that. But instead, you can make something similar using CSS:
label {display: block; padding: 5px; position: relative; padding-left: 20px;}
label input {display: none;}
label span {border: 1px solid #ccc; width: 15px; height: 15px; position: absolute; overflow: hidden; line-height: 1; text-align: center; border-radius: 100%; font-size: 10pt; left: 0; top: 50%; margin-top: -7.5px;}
input:checked + span {background: #ccf; border-color: #ccf;}
<h3>Select One</h3>
<label><input type="radio" name="select" /><span>a</span> Item 1</label>
<label><input type="radio" name="select" /><span>b</span> Item 2</label>
Preview
I'm trying to customize the radio and checkboxes using only css. I'm almost there except 2 little details:
here is a markup sample:
<section>
<label class="cbox radio">
<input name="how" type="radio" checked="checked" /> My first radio box
</label>
<label class="cbox radio">
<input name="how" type="radio" /> My second radio box
</label>
<label class="cbox radio">
<input name="how" type="radio" /> My third radio box
</label>
</section>
<section>
<label class="cbox box">
<input name="check1" type="checkbox" checked="checked" /> My first box
</label>
<label class="cbox box">
<input name="check2" type="checkbox" /> My second box
</label>
</section>
Every thing works fine but i can't make it work when the box is checked. I'm trying to use this pseudo class:
*::before, *::after {
box-sizing: border-box;
}
.cbox {
display: block;
position: relative;
margin: 10px 0;
padding-left: 35px;
cursor: pointer;
}
.cbox > input {
position: absolute;
left: -9999px;
}
.cbox::before, .cbox::after {
content: '';
position: absolute;
top: 0;
left: 0;
}
.cbox.radio::before, .cbox.radio::after {
border-radius: 50%;
}
.cbox::before {
display: block;
width: 20px;
height: 20px;
border: 1px solid #c1caca;
}
.cbox::after {
display: none;
width: 12px;
height: 12px;
margin: 4px;
background-color: #2e4a5d;
box-shadow: inset 0 15px 23px -10px rgba(187,230,240,.3),0 2px 2px rgba(0,0,0,.1);
}
/*input:checked + .cbox::before, input:hover + .cbox::before, */
.cbox.on::before, .cbox:hover::before {
background-color: #eaf1f6;
border-color: #a0afbb;
}
/* input:checked + .cbox::after, */
.cbox.on::after {
display: block;
}
And here the jquery
$(".cbox input").change(function() {
if($(this).is(':checked')) $(this).parent('label').toggleClass('on');
});
1- is there a way to make this css work?
2- since the selector :checked is only supported on IE9+, is it recommended to use selectivizr ? or is there a better fallback solution?
Thanks a lot
Just ditch the ::after pseudo class:
.cbox.radio input:checked { display: none; }
<label class="cbox radio">
<input name="how" type="radio" checked="checked" /> My first box
<input name="how2" type="radio" /> My first box
</label>
Fiddle: https://jsfiddle.net/84x66oux/
Btw, you won't be able to customize radios/checkboxes without hiding them in the first place, and adding the whole style yourself. Check this codepen for example
You can try this one
<style>
/*****************************************
RADIO BUTTONS
******************************************/
input[type="radio"] {
display: none;
}
input[type="radio"] + span {
background-color: #fefefe;
border: 1px solid;
border-color: #ccc #fff #fff #ccc;
border-radius: 50px;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
display: inline-block;
float: left;
margin-right: 7px;
padding: 7px;
position: relative;
-webkit-appearance: none;
}
input[type="radio"]:checked + span {
color: #f00;
}
input[type="radio"]:checked + span:after {
background: #f00;
border-radius: 50px;
box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.75), inset -1px -1px 1px rgba(0, 0, 0, 0.75);
content: " ";
height: 10px;
left: 2px;
position: absolute;
top: 2px;
width: 10px;
}
label:hover input[type="radio"] + span {
border-color: #900 #f00 #f00 #900;
}
</style>
<label>
<input type="radio" name="radio" value="1" checked> <span></span> Option first
</label>
$(".radio input").click(function() {
if ($(this).is(':checked')) {
$(".radio ").removeClass('on')
$(this).parent('label').addClass('on');
}
});
$(".box input").click(function() {
if ($(this).is(':checked')) {
$(this).parent('label').addClass('on');
} else {
$(this).parent('label').removeClass('on');
}
});
*::before,
*::after {
box-sizing: border-box;
}
.cbox {
display: block;
position: relative;
margin: 10px 0;
padding-left: 35px;
cursor: pointer;
}
.cbox > input {
position: absolute;
left: -9999px;
}
.cbox::before,
.cbox::after {
content: '';
position: absolute;
top: 0;
left: 0;
}
.cbox.radio::before,
.cbox.radio::after {
border-radius: 50%;
}
.cbox::before {
display: block;
width: 20px;
height: 20px;
border: 1px solid #c1caca;
}
.cbox::after {
display: none;
width: 12px;
height: 12px;
margin: 4px;
background-color: #2e4a5d;
box-shadow: inset 0 15px 23px -10px rgba(187, 230, 240, .3), 0 2px 2px rgba(0, 0, 0, .1);
}
/*input:checked + .cbox::before, input:hover + .cbox::before, */
.cbox.on::before,
.cbox:hover::before {
background-color: #eaf1f6;
border-color: #a0afbb;
}
/* input:checked + .cbox::after, */
.cbox.on::after {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section>
<label class="cbox radio">
<input name="how" type="radio" /> My first radio box
</label>
<label class="cbox radio">
<input name="how" type="radio" /> My second radio box
</label>
<label class="cbox radio">
<input name="how" type="radio" /> My third radio box
</label>
</section>
<section>
<label class="cbox box">
<input name="check1" type="checkbox" /> My first box
</label>
<label class="cbox box">
<input name="check2" type="checkbox" /> My second box
</label>
</section>
WHen I styled my checkbox, the label sits on top of the checkbox. But I want it to be separated. However due to the css I used, I find it very tricky because both checkbox and label shares the same with and height. Can someone suggest how to manipulate this label alone?
css
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label
{
background: #D9D9D9;
height: 40px;
width: 40px;
border-radius:20px;
display:inline-block;
padding: 0 0 0 0px;
cursor:pointer;
border:1px solid #00AAFF;
}
input[type=checkbox]:checked + label
{
background: #00B0F0;
height: 40px;
width: 40px;
border-radius:20px;
display:inline-block;
padding: 0 0 0 0px;
cursor:pointer;
}
here's the fiddle: http://jsfiddle.net/vxbbfyr0/
#container > div{
-webkit-user-select:none;
}
input[type=checkbox] {
display:none;
}
label span{
background: #D9D9D9;
height: 40px;
width: 40px;
border-radius: 20px;
display:inline-block;
vertical-align: middle;
padding: 0 0 0 0px;
cursor:pointer;
border:1px solid #00AAFF;
}
label input[type=checkbox]:checked + span{
background: #00B0F0;
}
<div id="container">
<div>
<label for="checkbox1">
<input type="checkbox" id="checkbox1" class="item"/>
<span></span>
Label 1
</label>
</div>
<div>
<label for="checkbox2"><input type="checkbox" id="checkbox2" class="item"/>
<span></span>
label 2</label>
</div>
<div>
<label for="checkbox3">
<input type="checkbox" id="checkbox3" class="item"/>
<span></span>
label 3</label>
</div>
</div>