How to make a custom radio input with label - html

I am trying to perform a custom radio input for gender, a user can only choose either between "female" and "male", but I realized that I cant see the checked radio to display when I click on it seems not to work (to be selected) when I click on it, I tried to find out what is causing the radio not to be checked but I can't find it out. It used to work with the checkboxes inputs could anyone help me please, I am probably missing something.
.profile__input .input__radio {
display: inline-block;
}
.blu-radio {
width: auto;
margin: 16px 16px 16px 0;
display: inline-flex;
position: relative;
}
.blu-radio:not(.b-disabled) {
cursor: pointer;
}
.blu-radio .blu-radio-container {
width: 20px;
min-width: 20px;
height: 20px;
position: relative;
border: 2px solid transparent;
border-radius: 50%;
transition: .4s cubic-bezier(0.25, 0.8, 0.25, 1);
border-color: #e0e0e0;
}
.blu-radio .blu-radio-container:before,
.blu-radio .blu-radio-container:after {
position: absolute;
transition: .4s cubic-bezier(0.55, 0, 0.55, 0.2);
content: " ";
}
.blu-radio .blu-radio-container:before {
width: 48px;
height: 48px;
top: 50%;
left: 50%;
z-index: 11;
border-radius: 50%;
transform: translate(-50%, -50%);
}
.blu-radio .blu-radio-container input {
position: absolute;
left: -999em;
}
.blu-radio .blu-radio-container:after {
position: absolute;
top: 3px;
right: 3px;
bottom: 3px;
left: 3px;
border-radius: 50%;
opacity: 0;
transform: scale3D(0.38, 0.38, 1);
content: " ";
}
.blu-radio .blu-radio-label {
padding-left: 8px;
position: relative;
line-height: 20px;
}
.blu-radio:not(.b-disabled) .blu-radio-label {
cursor: pointer;
color: rgba(0, 0, 0, 0.6);
}
<div class="profile__input">
<div class="input__title tx-gray">Genre</div>
<div class="input__radio">
<div class="blu-radio">
<div class="blu-radio-container">
<input type="radio" id="blu-radio-3as6fzz1" name='gender'>
</div>
<label for="blu-radio-3as6fzz1" class="blu-radio-label">Homme</label>
</div>
</div>
<div class="input__radio">
<div class="blu-radio">
<div class="blu-radio-container">
<input type="radio" id="blu-radio-v0okyps4r" name='gender'>
</div>
<label for="blu-radio-v0okyps4r" class="blu-radio-label">Femme</label>
</div>
</div>
</div>

Try this code instead, i'm using the input:checked to test if the radio is checked or not then i append to the fake radio a background color.
I put the fake radio container into the label, so when you click on it, it will check the real radio button wich is hidden.
.profile__input .input__radio {
display: inline-block;
}
.blu-radio {
width: auto;
margin: 16px 16px 16px 0;
display: inline-flex;
position: relative;
}
.blu-radio:not(.b-disabled) {
cursor: pointer;
}
.blu-radio .blu-radio-container {
width: 20px;
min-width: 20px;
height: 20px;
position: relative;
border: 2px solid transparent;
border-radius: 50%;
transition: .4s cubic-bezier(0.25, 0.8, 0.25, 1);
border-color: #e0e0e0;
display: inline-block;
position: relative;
top: 6px;
}
.blu-radio .blu-radio-container:before,
.blu-radio .blu-radio-container:after {
position: absolute;
transition: .4s cubic-bezier(0.55, 0, 0.55, 0.2);
content: " ";
}
.blu-radio .blu-radio-container:before {
width: 48px;
height: 48px;
top: 50%;
left: 50%;
z-index: 11;
border-radius: 50%;
transform: translate(-50%, -50%);
}
.blu-radio input {
display: none;
}
.blu-radio .blu-radio-container:after {
position: absolute;
top: 3px;
right: 3px;
bottom: 3px;
left: 3px;
border-radius: 50%;
opacity: 0;
transform: scale3D(0.38, 0.38, 1);
content: " ";
}
.blu-radio .blu-radio-label {
padding-left: 8px;
position: relative;
line-height: 20px;
}
.blu-radio input:checked + .blu-radio-label .blu-radio-container {
background: red;
}
.blu-radio:not(.b-disabled) .blu-radio-label {
cursor: pointer;
color: rgba(0, 0, 0, 0.6);
}
<div class="profile__input">
<div class="input__title tx-gray">Genre</div>
<div class="input__radio">
<div class="blu-radio">
<input type="radio" id="blu-radio-3as6fzz1" name='gender'>
<label for="blu-radio-3as6fzz1" class="blu-radio-label">
<span class="blu-radio-container"></span> Homme
</label>
</div>
</div>
<div class="input__radio">
<div class="blu-radio">
<input type="radio" id="blu-radio-v0okyps4r" name='gender'>
<label for="blu-radio-v0okyps4r" class="blu-radio-label">
<span class="blu-radio-container"></span> Femme
</label>
</div>
</div>
</div>

a basic one...
* {
font-size : 20px;
}
label > input[type="radio"] { display : none; }
label > input[type="radio"] + span {
--diameter : 1.4em;
display : inline-block;
height : var(--diameter);
line-height : var(--diameter);
cursor : pointer;
width : 6.2em;
position : relative;
box-sizing : border-box;
padding-left : calc(var(--diameter) + .3em);
color : #7d7d7d;
}
label > input[type="radio"]:checked + span {
color : black;
}
label > input[type="radio"] + span:before {
box-sizing : border-box;
width : var(--diameter);
height : var(--diameter);
border : 1px solid #7d7d7d;
border-radius : 50%;
position : absolute;
top : 0;
left : 0;
content : ' ';
}
label > input[type="radio"]:checked + span::after {
box-sizing : border-box;
position : absolute;
top : .1em;
left : .1em;
content : ' ';
width : calc(var(--diameter) - .2em);
height : calc(var(--diameter) - .2em);
border-radius : 50%;
background-color : #eb1641;
}
<label>
<input type="radio" name="gender">
<span>Homme</span>
</label>
<label>
<input type="radio" name="gender">
<span>Femme</span>
</label>

Related

The second text in <span> goes to another line

How do I display "Confirm Password" in a single line ?
I add an <span id="confirm">Confirm Password</span> and I did this, doesn't work:
#confirm {
display: inline;
}
* {
margin: 0px;
padding: 0px;
}
body {
background-color: Royalblue; /*#f0f0f0;*/
}
.head {
text-align: center;
border: 1px solid #B0C4DE;
border-bottom: none;
border-radius: 10px 10px 0px 0px;
padding: 20px;
background: rgba(0, 250, 0, 0);
color: #FFFACD;
font-family: 'Cinzel', sans-serif;
font-size:30px;
}
.content {
position:relative;
top:8px;
width: 30%;
margin: 50px
auto 0px;
}
form {
position: relative;
margin-top: 0;
margin-left: 0;
width: 89%;
height: 300px;
padding: 20px;
border: 1px solid #B0C4DE;
background: rgba(0, 250, 0, 0);
border-radius: 0px 0px 10px 10px;
}
label {
position: relative;
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
left: -65%;
top: -30px;
}
.username {
position: relative;
top: 65px;
}
.password {
position: relative;
top: 130px;
}
.con-pass {
position: relative;
top: 195px;
}
#confirm {
display: inline;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
border: 0;
border-bottom: 2px solid beige;
background: transparent;
font-size: 15px; /*BORDER yes/no*/
height: 25px;
width: 250px;
outline: 0;
z-index: 1;
left: -74px;
top: -30px;
}
span {
position: absolute;
top: 5px;
left: -6px;
transition: top .5s ease, font-size .5s ease;
}
input:focus + label > span,
input:valid + label > span {
top: -20px;
font-size: 11px;
/* padding-bottom: 15px;*/
}
label::after {
content: '';
position: absolute;
top: 27px; /* ::after position */
left: -7px;
width: 250px;
height: 23px;
border-radius: 2px;
transition: transform .3s;
}
label::after {
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: top;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1.3, 1);
transition-timing-function: linear;
top: 27px; /* ::after position */
}
input:focus {
border-radius: 2px;
}
<div class="content">
<p class="head">Register</p>
<form>
<div class="content">
<div class="email">
<input type="text" id="email" required /> <!--input field-->
<label for="email"><span>Email</span></label>
</div>
<div class="username">
<input type="text" id="user" required />
<label for="user"><span>Username</span></label>
</div>
<div class="password">
<input type="text" id="pass" required /> <!--input field-->
<label for="pass"><span>Password</span></label>
</div>
<div class="con-pass">
<input type="text" id="c-pass" required />
<label for="c-pass"><span id="confirm">Confirm Password</span></label>
</div>
</div>
</form>
</div>
You can use white-space: nowrap; for that :
#confirm {
white-space: nowrap;
}
Here is a resource for the white-space property in CSS.
Use white-space: nowrap; for class con-pass
You can also insert a in your html. That will ensure the two Words are kept on the same line:
<label for="c-pass"><span id="confirm">Confirm Password</span></label>

list item bullet points duplicated

I am building this simple form (took the code from here https://codepen.io/JeromeRenders/pen/EPNxPv ) but the bullet points end up being duplicated on my page. How come? Here following is the html for the form and the css I am using. Thank you. I also added JS because that is what is creating the li list.
body fieldset {
box-shadow: 0 8px 10px #29a329;
}
body.error {
background: #f04000;
}
body.error fieldset {
box-shadow: 0 8px 10px #bd3200;
}
ul.items {
position: absolute;
width: 30px;
height: auto;
top: 50%;
left: -60px;
transform: translateY(-50%);
}
ul.items li {
width: 8px;
height: 8px;
margin: 10px 0;
background: white;
border-radius: 50%;
opacity: 0.4;
cursor: pointer;
}
ul.items li.active {
opacity: 1;
}
form {
position: relative;
width: 300px;
height: 60px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
form fieldset {
position: absolute;
width: 300px;
height: 60px;
background: white;
border-radius: 3px;
opacity: 0;
transform: scale(0.2);
transition: all 0.4s ease-in-out;
}
form fieldset input,
form fieldset p {
display: inline-block;
width: 200px;
margin-left: 50px;
color: #333333;
font-size: 16px;
letter-spacing: 1px;
}
form fieldset p {
margin-top: 22px;
text-align: center;
}
form fieldset input {
height: 40px;
margin-top: 8px;
border: none;
outline: none;
}
body.error fieldset {
transform-origin: 50% 100%;
animation: error 0.3s ease-out;
}
<form>
<ul class="items"></ul>
<fieldset class="username enable">
<div class="icon left"><i class="user"></i></div>
<input type="text" name="username" placeholder="Username" />
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="email">
<div class="icon left"><i class="letter"></i></div>
<input type="mail" name="email" placeholder="Email" />
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="thanks">
<div class="icon left"></div>
<p>Thanks for your time</p>
<div class="icon right"></div>
</fieldset>
</form>
JS
function init() {
// Generate li foreach fieldset
for (var i = 0; i < count; i++) {
var ul = document.querySelector('ul.items'),
li = document.createElement("li");
ul.appendChild(li);
}
// Add class active on first li
ul.firstChild.classList.add('active');
}
Here is an image of what I get:
Duplicated bullet points
Below code useful for that:
css:
body {
background: #33cc33;
font-family: sans-serif;
}
body fieldset {
box-shadow: 0 8px 10px #29a329;
}
body.error {
background: #f04000;
}
body.error fieldset {
box-shadow: 0 8px 10px #bd3200;
}
h1, h2 {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-family: sans-serif;
text-transform: uppercase;
letter-spacing: 2px;
}
h1 {
top: 24px;
color: white;
font-size: 12px;
}
h2 {
top: 44px;
color: white;
font-size: 10px;
opacity: 0.7;
}
ul.items {
position: absolute;
width: 30px;
height: auto;
top: 50%;
left: -60px;
transform: translateY(-50%);
}
ul.items li {
width: 8px;
height: 8px;
margin: 10px 0;
background: white;
border-radius: 50%;
opacity: 0.4;
cursor: pointer;
}
ul.items li.active {
opacity: 1;
}
form {
position: absolute;
width: 300px;
height: 60px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
form fieldset {
position: absolute;
width: 300px;
height: 60px;
background: white;
border-radius: 3px;
opacity: 0;
transform: scale(0.2);
transition: all 0.4s ease-in-out;
}
form fieldset input, form fieldset p {
display: inline-block;
width: 200px;
margin-left: 50px;
color: #333333;
font-size: 16px;
letter-spacing: 1px;
}
form fieldset p {
margin-top: 22px;
text-align: center;
}
form fieldset input {
height: 40px;
margin-top: 8px;
border: none;
outline: none;
}
form fieldset .icon {
position: absolute;
width: 30px;
height: 30px;
top: 15px;
transition: all 0.4s ease;
}
form fieldset .icon i {
position: absolute;
display: block;
}
form fieldset .icon i::before, form fieldset .icon i::after {
position: absolute;
content: "";
}
form fieldset .icon.left {
left: 10px;
}
form fieldset .icon.right {
right: 10px;
cursor: pointer;
}
form fieldset .icon.button:hover {
background: #f2f2f2;
border-radius: 3px;
transition: all 0.4s ease;
}
form fieldset.enable {
z-index: 1;
opacity: 1;
transition: all 0.5s ease-out 0.2s;
transform: scale(1);
animation: enable 0.5s ease-out 0.2s;
}
form fieldset.disable {
opacity: 0;
transition: all 0.3s ease-in;
transform: translateY(120px) scale(0.9);
}
body.error fieldset {
transform-origin: 50% 100%;
animation: error 0.3s ease-out;
}
#keyframes enable {
0% {
opacity: 0;
transform: scale(0.2);
}
60% {
transform: scale(1.1);
}
100% {
opacity: 1;
transform: scale(1);
}
}
#keyframes error {
0%, 50%, 100% {
transform: rotate(0deg);
}
25% {
transform: rotate(-3deg);
}
75% {
transform: rotate(3deg);
}
}
/**
* Icons in CSS, long as f****
*/
.icon .arrow {
width: 2px;
height: 17px;
top: 5px;
left: 14px;
background: #333333;
}
.icon .arrow::before {
width: 6px;
height: 6px;
bottom: -1px;
left: -3px;
border-color: #333333;
border-right: 2px solid;
border-bottom: 2px solid;
transform: rotate(45deg);
}
.icon .user {
width: 20px;
height: 10px;
bottom: 5px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 6px 6px 3px 3px;
}
.icon .user::before {
width: 10px;
height: 10px;
top: -9px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 50%;
}
.icon .letter {
width: 20px;
height: 12px;
top: 9px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 3px;
}
.icon .letter::before, .icon .letter::after {
width: 11px;
height: 2px;
top: 4px;
background: #333333;
}
.icon .letter::before {
left: 0;
transform: rotate(30deg);
}
.icon .letter::after {
right: 0;
transform: rotate(-30deg);
}
.icon .lock {
width: 20px;
height: 16px;
top: 9px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 3px;
}
.icon .lock::before {
width: 8px;
height: 8px;
top: -4px;
left: 4px;
border: 2px solid transparent;
border-top: 2px solid #333333;
border-right: 2px solid #333333;
border-radius: 50%;
transform: rotate(-45deg);
}
.icon .lock::after {
width: 6px;
height: 7px;
top: 4px;
left: 7px;
box-shadow: 0 0 0 2px #333333 inset;
}
.icon .heart {
width: 10px;
height: 10px;
top: 11px;
left: 7px;
background: #ff5233;
transform: rotate(45deg);
}
.icon .heart::before, .icon .heart::after {
width: 10px;
height: 10px;
border-radius: 50%;
background: #ff5233;
}
.icon .heart::before {
left: -6px;
}
.icon .heart::after {
top: -6px;
}
HTML:
<form>
<ul class="items"><li class="active"></li><li></li><li></li><li></li></ul>
<fieldset class="username enable">
<div class="icon left"><i class="user"></i></div>
<input type="text" name="username" placeholder="Username"/>
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="email">
<div class="icon left"><i class="letter"></i></div>
<input type="mail" name="email" placeholder="Email"/>
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="password">
<div class="icon left"><i class="lock"></i></div>
<input type="password" name="password" placeholder="Password"/>
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="thanks">
<div class="icon left"><i class="heart"></i></div>
<p>Thanks for your time</p>
<div class="icon right"><i class="heart"></i></div>
</fieldset>
</form>
JS:
function init() {
// Generate li foreach fieldset
for (var i = 0; i < count; i++) {if (window.CP.shouldStopExecution(1)){break;}
var ul = document.querySelector('ul.items'),
li = document.createElement("li");
ul.appendChild(li);
}
window.CP.exitedLoop(1);
// Add class active on first li
ul.firstChild.classList.add('active');
}
function next(target) {
var input = target.previousElementSibling;
// Check if input is empty
if (input.value === '') {
body.classList.add('error');
} else {
body.classList.remove('error');
var enable = document.querySelector('form fieldset.enable'),
nextEnable = enable.nextElementSibling;
enable.classList.remove('enable');
enable.classList.add('disable');
nextEnable.classList.add('enable');
// Switch active class on left list
var active = document.querySelector('ul.items li.active'),
nextActive = active.nextElementSibling;
active.classList.remove('active');
nextActive.classList.add('active');
}
}
function keyDown(event) {
var key = event.keyCode,
target = document.querySelector('fieldset.enable .button');
if (key == 13 || key == 9) next(target);
}
var body = document.querySelector('body'),
form = document.querySelector('form'),
count = form.querySelectorAll('fieldset').length;
window.onload = init;
document.body.onmouseup = function (event) {
var target = event.target || event.toElement;
if (target.classList.contains("button")) next(target);
};
document.addEventListener("keydown", keyDown, false);

Input checked state does not affect css selector

So I've been trying to trigger my CSS selector via the checkbox state as you can see below but I've had no luck getting it to trigger. What should happen on click is the tick should simply disappear.
.i-cb input[type="checkbox"]:checked + label::before {
display: none;
width:0px;
height: 0px;
}
JSFiddle : https://jsfiddle.net/7tnepc8r/4/
It's a problem with order.
You should change order your HTML.
The + selector is used to select elements that is placed immediately after(not inside) the first specified element.
.i-cb input[type=checkbox] {
visibility: hidden;
}
.i-cb label {
position: relative;
display: inline-block;
width: 44px;
height: 44px;
border: 4px solid #48c8f1;
border-radius: 50%;
border-top-color: transparent;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
z-index: 0;
}
.i-cb label::before {
content: "";
position: absolute;
width: 6px;
height: 45px;
background-color: #93c83d;
left: 22px;
top: -15px;
z-index: 1;
}
.i-cb label::after {
content: "";
position: absolute;
width: 18px;
height: 6px;
background-color: #93c83d;
left: 10px;
top: 24px;
z-index: 1;
}
.i-cb input[type=checkbox]:checked + label::after {
display: none !important;
width: 0px !important;
height: 0px !important;
}
.i-cb input[type=checkbox]:checked + label::before {
display: none;
width: 0px;
height: 0px;
}
<div class="i-cb">
<input id="check" type="checkbox" />
<label for="check"></label>
</div>
You just need change the markup order, because you using + sign which indicating label after input:
<div class="i-cb">
<input id="check" type="checkbox" />
<label for="check"></label>
</div>

Custom checkboxes move slightly when selected

I modified the checkboxes in my project to look more aligned with the rest of the design but I have a problem: whenever selected the label of the checkbox moves slightly.
input[type="checkbox"] {
display: none !important;
}
input[type="checkbox"]+label:before {
position: relative;
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label:before {
position: relative;
content: "✔";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
<input type="checkbox" />
<label>Click to accept</label>
Here's the result:
And here's what happens if I select it:
What am I doing wrong?
Nowadays and for awhile you can fix this if you set the parent to display:flex
input[type="checkbox"] {
display: none !important;
}
label {
display: flex;
/* just to vertically the text with the box */
align-items: center
}
input[type="checkbox"]+label::before {
content: "";
display: block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label::before {
content: "✔";
/* just to center inside the box */
display: grid;
place-content: center;
}
<input id="input" type="checkbox" />
<label for="input">Click to accept</label>
OLD ANSWER
To fix the "moving" you need to:
set vertical-align: some value in label::before I have choose bottom.
And to align the "✔" (in case it doesn't - snippet isn't), you need to:
add text-align:center and line-height:22px (same as the height) in :checked+label::before
input[type="checkbox"] {
display: none !important;
}
input[type="checkbox"]+label::before {
position: relative;
content: " ";
display: inline-block;
vertical-align: bottom;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label::before {
content: "✔";
text-align: center;
line-height: 22px;
}
<input id="input" type="checkbox" />
<label for="input">Click to accept</label>
NB: In both answers I removed duplicated properties and you're missing the for attribute in label to match id in input, otherwise you can't click in the pseudo checkbox, only in the label
You can see another way here.
See below working example:
/*--CSS--*/
input[type="checkbox"] {
-webkit-appearance: none;
background-color: transparent;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: pointer;
padding: 1px;
border-width: 0;
border-style: inset;
border-color: initial;
border-image: initial;
float: left;
margin: 0 25px 0 0;
position: relative;
}
input[type="checkbox"]:after {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
content: "";
position: absolute;
left: 0;
z-index: 1;
width: 16px;
height: 16px;
border: 1px solid #c0c0c0;
top:0;
}
input[type="checkbox"]:before {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
content: "";
position: absolute;
left: 0;
z-index: 1;
width: 16px;
height: 16px;
border: 1px solid #c0c0c0;
top:0;
opactity:0;
}
input[type="checkbox"]:checked:before {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
height: 5px;
border-color: #009688;
border-top-style: none;
border-right-style: none;
outline: none;
opacity: 1;
width: 12px;
top: 3px;
left: 3px;
}
input[type="checkbox"]:focus{outline:0;}
<!--HTML-->
<input type="checkbox" />
<label>Click to accept</label>
I have used a flexbox for the label to align the items vertically. Adding text-align:center when the checkbox is checked, ensures the marker is horizontally centered.
label {
display: flex;
align-items: center;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]+label:before {
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin-right: 0.5em;
}
input[type="checkbox"]:checked+label:before {
content: "✔";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin-right: 0.5em;
text-align: center;
}
<input type="checkbox" id="accept" />
<label for="accept">Click to accept</label>
you can try this, this is working
input[type="checkbox"] {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
}
input[type="checkbox"] + label:before {
position: relative;
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: -8px 10px 0 0;
vertical-align: middle;
}
input[type="checkbox"]:checked + label:before {
content: "✔";
text-align: center;
line-height: 22px;
}
<input type="checkbox"/>
<label>Click to accept</label>

CSS Only Multiple onclick events

This is generally a hack which i am trying to figure out in css, From what I can gather it should be working in theory and it isn't.
#expand {
width: 30px;
height: 30px;
background-color: rgba(0, 0, 0, 0);
}
#btn {
display: none;
}
#btn:checked+label:before {
transform: rotate(90deg);
}
#btn:checked+label:after {
transform: rotate(180deg);
}
#btn:checked+.button:before {
display: none;
}
#btn:checked+.button:after {
display: inline-block;
}
.button {
position: relative;
width: 25px;
height: 25px;
display: inline-block;
}
.button:before,
.button:after {
content: "";
position: absolute;
background-color: black;
transition: transform 0.35s ease-out;
}
/* Vert Line */
.button:before {
top: 0;
left: 46%;
width: 4px;
height: 100%;
margin-left: 2px;
margin-top: 2px;
}
/* Horiz Line */
.button:after {
top: 50%;
left: 0;
width: 100%;
height: 4px;
margin-left: 2px;
}
.inform {
display: none;
}
<div id="expand">
<input id="btn" type="checkbox">
<label class="button" for="btn"></label>
<div class="inform">
<h3>Heading</h3>
<p>Alot of content.</p>
</div>
So as you can see, I have the "hack" for the click event on changing the style for .button using a checkbox.
I then used the + selector to target the div .inform.
If i am correct the + selector means it targets the immediate following element, In which case this should work. But it does not, Could someone possibly help clear my understanding of this and if i am wrong, otherwise could you help point me in the right direction to get this to work.
Summary:
I would like to get the header and paragraph to display when the checkbox is checked, aswell as getting the + symbol to rotate.
You've got similar selectors:
#btn:checked+.button:before {
display: none;
}
#btn:checked+.button:before {
display: inline-block;
}
And #btn:checked+label:before and #btn:checked+.button:before are the same thing.
I think it should look like:
#expand {
width: 30px;
height: 30px;
background-color: rgba(0, 0, 0, 0);
}
#btn {
display: none;
}
#btn:checked+label:before {
transform: rotate(90deg);
}
#btn:checked+label:after {
transform: rotate(180deg);
}
#btn:checked+.button:before {
display: none;
}
#btn:checked ~ .inform {
opacity: 1;
}
.button {
position: relative;
width: 25px;
height: 25px;
display: inline-block;
}
.button:before,
.button:after {
content: "";
position: absolute;
background-color: black;
transition: transform 0.35s ease-out;
}
/* Vert Line */
.button:before {
top: 0;
left: 46%;
width: 4px;
height: 100%;
margin-left: 2px;
margin-top: 2px;
}
/* Horiz Line */
.button:after {
top: 50%;
left: 0;
width: 100%;
height: 4px;
margin-left: 2px;
}
.inform {
display: inline-block;
opacity: 0;
transition: all .5s ease;
}
<div id="expand">
<input id="btn" type="checkbox">
<label class="button" for="btn"></label>
<div class="inform">
<h3>Heading</h3>
<p>Alot of content.</p>
</div>