How to make a checkbox become clickable?

Asked

Viewed 167 times

0

Someone knows how to make the checkbox clickable. I created a new look for my checkbox, but when clicking on the checkbox it is not selected. I want the checkbox to be white and only when it is selected do your background turn green, as in the image below:

inserir a descrição da imagem aqui

Follow the CSS of what was done:

body {
    display: flex;
    background-color: #f5f5f5;
    font-family: Arial, sans-serif;
}

section#principal {
    width: 100%;
}

section#principal .modulo .container {
    height: ;
    padding: 20px;
}

section#principal .modulo .container .canvas {
    background-color: #ffffff;
    border: 1px solid #e6e6e6;
    border-radius: 4px;
    padding: 20px;
}

form ul {
    padding: 0; margin: 0;
    margin-bottom: 30px;
}

form li {
    list-style: none;
    margin-bottom: 10px;
}

form h2 {
    font-size: 20px;
    color: #161616;
    padding: 0; margin: 0;
    margin-bottom: 20px;
}

.confirmacoes li {
    font-size: 14px;
    display: flex;
    width: 400px;
}

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

.quadrado {
  width: 16px;
  height: 16px;
	margin-right: 5px;
	position: relative;
}

.quadrado label {
	cursor: pointer;
	position: absolute;
	width: 16px;
	height: 16px;
	top: 0;
  left: 0;
	background: #ffffff;
	border:1px solid #cdcdcd;
    border-radius: 2px;
}

.quadrado label:hover {
    background: #3aca60;
}

.quadrado label:after {
	opacity: 0;
  content: '';
	position: absolute;
	width: 7px;
	height: 3px;
	background: transparent;
	top: 4px;
	left: 3px;
	border: 3px solid #ffffff;
	border-top: none;
	border-right: none;

	transform: rotate(-45deg);
}

.quadrado label:hover::after {
	opacity: 0.5;
}

}
  input[type=checkbox] {
    visibility: hidden;
    &:checked + label:after {
      opacity: 1;
    }
  }    
}
<body>                        
 <section id="principal">
    
     <div class="modulo">
          
        <div class="container">
            <div class="canvas">
                
                <form action="">                     
                                      
                    <h2>Anythings</h2>
                    <ul class="confirmacoes">
                        <li>
                            <div class="quadrado">
                            <input type="checkbox"/>
                            <label for="checkboxOneInput"></label>
                           </div>
                           
                            <label>Güncelleme ve yenilikleri mail olarak almak istiyorum.</label>
                            
                        </li>
                        
                        <li>
                          
                           <div class="quadrado">
                            <input type="checkbox"  checked="checked"/>
                            <label for="checkboxOneInput"></label>
                            </div>
                            
                            <label>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras id nisl eget nunc molestie maximus.</label>
                            
                        </li>
                    </ul>
                                       
                </form>
                
            </div>
        </div>
        
     </div>
     
 </section>              
</body>

1 answer

3

Utilize bootstrap and prefixfree to make things easier. For this is already something more advanced.

.cbx {
  position: relative;
  top: 1px;
  width: 17px;
  height: 17px;
  border: 1px solid #c8ccd4;
  border-radius: 3px;
  vertical-align: middle;
  transition: background 0.1s ease;
  cursor: pointer;
}
.cbx:after {
  content: '';
  position: absolute;
  top: 1px;
  left: 5px;
  width: 5px;
  height: 11px;
  opacity: 0;
  transform: rotate(45deg) scale(0);
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transition: all 0.3s ease;
  transition-delay: 0.15s;
}
.lbl {
  margin-left: 5px;
  vertical-align: middle;
  cursor: pointer;
}
#cbx:checked ~ .cbx {
  border-color: transparent;
  background: green;
  animation: jelly 0.6s ease;
}
#cbx:checked ~ .cbx:after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}
.cntr {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  text-align: center;
}
@-moz-keyframes jelly {
  from {
    transform: scale(1, 1);
  }
  30% {
    transform: scale(1.25, 0.75);
  }
  40% {
    transform: scale(0.75, 1.25);
  }
  50% {
    transform: scale(1.15, 0.85);
  }
  65% {
    transform: scale(0.95, 1.05);
  }
  75% {
    transform: scale(1.05, 0.95);
  }
  to {
    transform: scale(1, 1);
  }
}
@-webkit-keyframes jelly {
  from {
    transform: scale(1, 1);
  }
  30% {
    transform: scale(1.25, 0.75);
  }
  40% {
    transform: scale(0.75, 1.25);
  }
  50% {
    transform: scale(1.15, 0.85);
  }
  65% {
    transform: scale(0.95, 1.05);
  }
  75% {
    transform: scale(1.05, 0.95);
  }
  to {
    transform: scale(1, 1);
  }
}
@-o-keyframes jelly {
  from {
    transform: scale(1, 1);
  }
  30% {
    transform: scale(1.25, 0.75);
  }
  40% {
    transform: scale(0.75, 1.25);
  }
  50% {
    transform: scale(1.15, 0.85);
  }
  65% {
    transform: scale(0.95, 1.05);
  }
  75% {
    transform: scale(1.05, 0.95);
  }
  to {
    transform: scale(1, 1);
  }
}
@keyframes jelly {
  from {
    transform: scale(1, 1);
  }
  30% {
    transform: scale(1.25, 0.75);
  }
  40% {
    transform: scale(0.75, 1.25);
  }
  50% {
    transform: scale(1.15, 0.85);
  }
  65% {
    transform: scale(0.95, 1.05);
  }
  75% {
    transform: scale(1.05, 0.95);
  }
  to {
    transform: scale(1, 1);
  }
}
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>

<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>

<div class="cntr">
<input class="hidden-xs-up" id="cbx" type="checkbox" /><label class="cbx" for="cbx"></label><label class="lbl" for="cbx">Clique e veja!</label>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.