I have this piece of HTML (placed on CSSDesk):
<section style="margin-top: 50px;">
<header style="margin-bottom: 30px;">My checkboxes</header>
<div class="checkbox">
<input type="checkbox" id="checkbox"/>
<label for="checkbox"></label>
</div>
</section>
And this piece of CSS, also placed on CSSDesk:
input[type="checkbox"]{
display: none;
}
.checkbox{
position: relative;
width: 60px;
height: 2px;
background-color: black;
border-radius: 10%;
}
.checkbox input[type="checkbox"] + label{
top: -10px;
cursor: pointer;
position: absolute; /*otherwise ,,left: x px;" isn't working*/
display: block;
width: 20px;
height: 20px;
border-radius: 100%;
background-color: blue;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
}
.checkbox input[type="checkbox"]:checked + label{
left: 80%;
}
Impressed by Paul Underwood checkboxes I follow his tutorial: How To Style A Checkbox With CSS. Unfortunately, transition (I copied in 100% from tutorial) didn't work. And I don;t have any idea why. Here is my entire code, placed in CSS Desk: CSS Desk Decorative checkboxes. I will be pleased if anybody decides to help me - thank you in advance. My browser - Opera 25.0
You forgot to insert left: 0px in .checkbox label{...} class , because you expect that transition will be applied to transformation in x-Axis. Here is a working snippet.
input[type="checkbox"] {
display: none;
}
.checkbox {
position: relative;
width: 60px;
height: 2px;
background-color: black;
border-radius: 10%;
}
.checkbox label {
/*insert next line*/
left: 0px;
top: -10px;
cursor: pointer;
position: absolute;
/*otherwise ,,left: x px;" isn't working*/
display: block;
width: 20px;
height: 20px;
border-radius: 100%;
background-color: blue;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
}
.checkbox input[type="checkbox"]:checked + label {
left: 80%;
}
<section style="margin-top: 50px;">
<header style="margin-bottom: 30px;">My checkboxes</header>
<div class="checkbox">
<input type="checkbox" id="checkbox" />
<label for="checkbox"></label>
</div>
</section>
Related
In Chrome, firefox, opera, brave ia ok, in Safari - transition no good.
In Edge, Internet Esplorer - apprearance not work, looks like the checkbox
How to repear safari's transition and apprearance in Edge/IE browsers?
.mytoggle {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 80px;
height: 30px;
display: inline-block;
position: relative;
border-radius: 15px;
overflow: hidden;
outline: none;
border: none;
cursor: pointer;
background-color: #bdc3c7;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}
.mytoggle:before {
width: 22px;
height: 22px;
left: 4px;
top: 4px;
border-radius: 11px;
z-index: 2;
content: "ON OFF";
display: block;
position: absolute;
background: #7f8c9a;
font-size: 14.99px;
font-weight: 700;
text-transform: uppercase;
text-indent: -32px;
word-spacing: 40px;
color: #fff;
white-space: nowrap;
-webkit-transition: .25s ease-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}
.mytoggle:checked {
background-color: #2A3542;
}
input.mytoggle:focus {
outline: 0;
}
.mytoggle:checked:before {
background-color: #41cac0;
color: #41cac0;
left: 54px;
}
<input type="checkbox" checked="checked" class="mytoggle" style="" />
Styling a checkbox directly is a pain, you could use the checkbox + label hack, in which you link a label to a checkbox, and apply the styles to the label instead of the checkbox itself:
.mytoggle {
visibility: hidden;
opacity: 0;
position: absolute;
top: -99999px;
}
.mytoggle + label {
font-family: arial;
vertical-align: middle;
width: 80px;
height: 30px;
display: inline-block;
position: relative;
border-radius: 15px;
overflow: hidden;
outline: none;
border: none;
cursor: pointer;
background-color: #bdc3c7;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}
.mytoggle + label:before {
width: 22px;
height: 22px;
left: 4px;
top: 4px;
border-radius: 11px;
z-index: 2;
content: "ON OFF";
display: block;
position: absolute;
background: #7f8c9a;
font-size: 14.99px;
font-weight: 700;
text-transform: uppercase;
text-indent: -32px;
word-spacing: 40px;
color: #fff;
white-space: nowrap;
-webkit-transition: .25s ease-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}
.mytoggle:checked + label {
background-color: #2A3542;
}
input.mytoggle:focus + label {
outline: 0;
}
.mytoggle:checked + label:before {
background-color: #41cac0;
color: #41cac0;
left: 54px;
}
<input type="checkbox" checked="checked" class="mytoggle" id="mycheckbox" />
<label for="mycheckbox" />
input { opacity:0}
input+label {
width: 80px;
height: 30px;
display: inline-block;
position: relative;
border-radius: 15px;
overflow: hidden;
outline: none;
border: none;
cursor: pointer;
background-color: #bdc3c7;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}
input+label:before {
width: 22px;
height: 22px;
left: 4px;
top: 4px;
border-radius: 11px;
z-index: 2;
content: "ON OFF";
display: block;
position: absolute;
background: #7f8c9a;
font-size: 14.99px;
font-weight: 700;
text-transform: uppercase;
text-indent: -32px;
word-spacing: 40px;
color: #fff;
white-space: nowrap;
-webkit-transition: .25s ease-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}
input:checked+label{
background-color: #2A3542;
}
input.mytoggle:focus {
outline: 0;
}
input:checked+label:before {
background-color: #41cac0;
color: #41cac0;
left: 54px;
}
<input type="checkbox" name="abc" id="abc" checked="checked" style="" />
<label for="abc" class="mytoggle"></label>
I just added a label for input checkbox, tested in internet explorer 11. I don't have have safari browser to test it, So you can test and let know, if this answer meets your requirement.
Please try this.
$(document).ready(function(e) {
$(".ra-box").click(function(){
$(this).toggleClass('checked');
});
});
input[type=checkbox] { opacity: 0; }
.ra-box {
display: inline-block;
margin: 0;
padding: 6px;
cursor: pointer;
border-radius: 15px;
overflow: hidden;
background: #2a3542;
width: 70px;
height: 18px;
position: relative;
}
.ra-box:before {
height: 20px;
width: 20px;
background: #41cac0;
color: #41cac0;
content: 'ON';
text-indent: -40px;
position: absolute;
top: 5px;
right: 5px;
border-radius: 50%;
}
.ra-box:after {
height: 20px;
width: 20px;
background: #7f8c9a;
color: #fff;
content: 'OFF';
position: absolute;
top: 5px;
border-radius: 50%;
text-indent: 30px;
left: 85px;
}
/* Check Box Check Change background color */
.ra-box.checked:before { right: 85px; }
.ra-box.checked:after { left: 5px;}
.ra-box.checked { background: #bdc3c7; }
.ra-box,.checked,.ra-box.checked,.ra-box:before,.ra-box:after,.ra-box.checked:before,.ra-box.checked:after {
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ra-box">
<input type="checkbox" id="toggle-1">
</div>
<br>
<br>
<div class="ra-box">
<input type="checkbox" id="toggle-1">
</div>
I have a product listing little square thing, when I click it ( it's a label ) it should tick the box and it does but it should make the border green and hold it but it doesn't I have this:
.product {
width: 100%;
background: #fff;
border: 4px solid #fff;
border-radius: 4px;
margin-bottom: 20px;
box-shadow: 0 2px 3px #ddd;
text-align:center;
padding-bottom: 15px;
cursor: pointer;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
a {
color: #d6d6d6;
line-height: 25px;
border-radius: 100%;
background: #f2f2f2;
width: 25px;
height: 25px;
display: block;
position: absolute;
margin: 10px;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
&:hover {
background: #e2e1e1;
color: #333;
text-decoration: none
}
}
img {
width: 80%;
margin: 15px auto;
pointer-events: none;
}
span {
display: block;
&.brand {
color: #cdcfd2;
font-size: 13px;
font-weight: 300;
}
&.name {
color: #232f3e;
font-size: 16px;
font-weight: 600;
}
}
&:hover {
border: 4px solid #d9dce1;
box-shadow: none;
}
}
and this works great it's .less my html looks like this:
<div class="col-md-2">
<label for="product_id" name="product_id" class="product">
i
<div class="position">
<input type="checkbox" class="checkbox" name="product_id" id="product_id">
</div>
<img src="assets/images/products/image.jpg">
<span class="brand">Brand</span>
<span class="name">Product</span>
</label>
How do I would I apply the suggestions in this checked: example?
input[type=checkbox]:checked + label { }
It looks pretty simple but when I add it it doesn't work all I want is the .product border to be green instead of grey when it's selected
I know I can use js but I don't want to css should do it.
+ is an adjacent sibling selector, meaning it matches the element after it based on the selector. Simply add a label tag after your <input type="checkbox"> tag.
.product {
width: 100%;
background: #fff;
border: 4px solid #fff;
border-radius: 4px;
margin-bottom: 20px;
box-shadow: 0 2px 3px #ddd;
text-align: center;
padding-bottom: 15px;
cursor: pointer;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.product a {
color: #d6d6d6;
line-height: 25px;
border-radius: 100%;
background: #f2f2f2;
width: 25px;
height: 25px;
display: block;
position: absolute;
margin: 10px;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.product a:hover {
background: #e2e1e1;
color: #333;
text-decoration: none;
}
.product img {
width: 80%;
margin: 15px auto;
pointer-events: none;
}
.product span {
display: block;
}
.product span.brand {
color: #cdcfd2;
font-size: 13px;
font-weight: 300;
}
.product span.name {
color: #232f3e;
font-size: 16px;
font-weight: 600;
}
.product:hover {
border: 4px solid #d9dce1;
box-shadow: none;
}
input[type=checkbox]:checked + label {
color: red;
}
<div class="col-md-2">
<label for="product_id" name="product_id" class="product">
i
<div class="position">
<input type="checkbox" class="checkbox" name="product_id" id="product_id">
<label for="product_id">label</label>
</div>
<img src="assets/images/products/image.jpg">
<span class="brand">Brand</span>
<span class="name">Product</span>
</label>
to work "+" tags need to go one by one
css:
input[type=checkbox]:checked + label { }
html:
<input type="checkbox" id="id"><label for="id">...</label>
input[type=checkbox]:checked + label {
background-color: red;
}
<input type="checkbox" id="id">
<label for="id">Test</label>
For anyone struggling
The input and the element that you're modifying need to be directly next to the each other, for the :checked rule to work.
#hidden {
display: none;
height: 100px;
background: red;
}
:checked + #hidden {
display: block;
}
<input type="checkbox" id="my_checkbox" style="display:none;">
<!-- NEED TO BE NEXT TO EACH OTHER ^ -->
<div id="hidden"></div>
<label for="my_checkbox">Show/hide</label>
I'm trying to make a play button. I've run in to some trouble trying to get the play triangle to center in the circle. I've been trying to figure this out with no avail so I thought I'd ask you guys and gals!
If you have any other suggestions on how to do this I would love to know!
Thanks guys!
HTML:
<a href="#">
Learn more
<br>
<i class="fa fa-angle-down"></i>
</a>
CSS:
#play-btn{
height: 100px;
width: 100px;
margin: 0 auto;
position: relative;
display: inline-block;
box-sizing: border-box;
border: 3px solid #FFF;
border-radius: 50%;
opacity: .7;
}
#play-btn:hover{
opacity: 1;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-ms-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
}
.fa-play{
position: relative;
top: 50%;
color: #FFF;
opacity: .7;
font-size: 50px;
transform: translateY(-50%);
}
.fa-play:hover{
color: #FFF;
opacity: 1;
}
http://codepen.io/anon/pen/grpzmr
Just apply the text-align:center; in the #play-btn to center its contents:
#play-btn {
height: 100px;
width: 100px;
margin: 0 auto;
position: relative;
display: inline-block;
box-sizing: border-box;
border: 3px solid #FFF;
border-radius: 50%;
opacity: .7;
text-align: center;
}
Your updated pen.
Actually You just need to make minor modification with your CSS.
Just add the below CSS for the class #play-btn, and your problem will be resolved.
text-align:center;
padding-left: 10px;
Or Check it out below updated code :
HTML :
<a href="#">
Learn more
<br>
<i class="fa fa-angle-down"></i>
</a>
CSS :
#play-btn{
height: 100px;
width: 100px;
margin: 0 auto;
position: relative;
display: inline-block;
box-sizing: border-box;
border: 3px solid #FFF;
border-radius: 50%;
opacity: .7;
text-align:center;
padding-left: 10px;
}
#play-btn:hover{
opacity: 1;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-ms-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
}
.fa-play{
position: relative;
top: 50%;
color: #FFF;
opacity: .7;
font-size: 50px;
transform: translateY(-50%);
}
.fa-play:hover{
color: #FFF;
opacity: 1;
}
Just copy and paste and check it out i hope this will help you.
I'm looking for some help to move my checkbox label after the label has been checked. When it starts out, the label is in the middle of the code. After I click on it, however, I would like for it to be moved. I thought that I had it, but it doesn't look that way now. Is there anybody that would be willing to lend a hand?
JSFiddle: http://jsfiddle.net/50c419nL/4/
Markup:
<div id="vera-gallery">
<div class="vera-check">
<label for="vone">e x i l e</label>
<input type="checkbox" id="vone" name="main" />
<div class="vera-bar">I'm controlled by toggle. No JavaScript!</div>
</div>
</div>
CSS:
#vera-gallery {
width: 500px;
height: 500px;
overflow: hidden;
background-image:url(http://i.imgur.com/ZOmzzeE.png);
margin: auto;
position: relative;
}
#vera-gallery input[type=checkbox] {
display: none;
}
.vera-check {
width: 500px;
height: 500px;
}
.vera-check input[type=checkbox] {
position: absolute;
top: 50%;
left: 50%;
}
.vera-check input[type=checkbox]:checked ~ .vera-bar {
margin-left: 0;
}
.vera-check label {
cursor: pointer;
}
.vera-check label[for=vone] {
top: 235px;
width: 80px;
text-align: center;
font-family: oxygen;
font-size: 8px;
text-transform: uppercase;
letter-spacing: 1px;
color: #fff;
text-align: center;
padding: 10px;
position: absolute;
background-color: rgba(0, 0, 0, 0.8);
left: 200px;
border: 1px solid #fff;
}
.vera-check input[type=checkbox]:checked ~ label[for=vone] {
top: 10px;
left: 10px;
}
.vera-bar {
width: 470px;
padding: 15px;
background-color: rgba(0, 0, 0, 0.8);
float: left;
top: 0px;
height: 100%;
font-family: oxygen;
font-weight: bold;
color: #fff;
margin-left: -500px;
transition: 0.5s all ease;
-webkit-transition: 0.5s all ease;
-moz-transition: 0.5s all ease;
-ms-transition: 0.5s all ease;
-o-transition: 0.5s all ease;
}
.vera-ships {
width: 225px;
padding: 15px;
background-color: rgba(0, 0, 0, 0.8);
float: left;
top: 0px;
height: 100%;
font-family: oxygen;
font-weight: bold;
color: #fff;
margin-left: -255px;
transition: 0.5s all ease;
-webkit-transition: 0.5s all ease;
-moz-transition: 0.5s all ease;
-ms-transition: 0.5s all ease;
-o-transition: 0.5s all ease;
}
.vera-two {
position: absolute;
}
.vera-two .vera-chk {
float: left
}
.vera-two input[type=checkbox] {
display: none
}
The general sibling selector will not work in this case, with the markup as-is, since the checkbox input does not precede the label.
The ~ combinator separates two selectors and matches the second
element only if it is preceded by the first, and both share a common
parent.
If, however, you move the label after the div, it works: http://jsfiddle.net/50c419nL/5/
<div id="vera-gallery">
<div class="vera-check">
<input type="checkbox" id="vone" name="main" />
<div class="vera-bar">I'm controlled by toggle. No JavaScript!</div>
<label for="vone">e x i l e</label><!-- moved to here -->
</div>
</div>
I'm trying to create a right and left off-screen navigation drawer with only css and I'm having problems getting each side to work properly.
I'm using checkboxes as my buttons like this:
<input type="checkbox" id="toggle-right">
<input type="checkbox" id="toggle-left">
If I have the toggle-right place on top then the right drawer opens, but not the left.
If I reverse the order like this:
<input type="checkbox" id="toggle-left">
<input type="checkbox" id="toggle-right">
Toggle left will work, but not toggle right.
I made a JSFiddle to show you what I mean.
If someone has time to take a look and help me figure this out I would appreciate it.
While reviewing the JSFiddle, reverse the order of the checkbox toggles to see what I'm talking about.
The problem lies with the usage of + - adjacent sibling selector. As it works only for next element to your checkbox, it will only works for one of them. The solution is to use ~ - general sibling selector.
header {
width: 100%;
height: 90px;
background-color:#f1f1f1;}
.menu-toggle {
text-decoration: none;
text-align: center;
width: 44px;
height: 44px;
font-size: 30px;
color: rgba(0, 0, 0, 0.5);
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
position: absolute;
top: 0px;
right: auto;
bottom: 0;
left: 20px;
z-index: 2; }
.menu-toggle:hover {
color: #000000; }
#toggle-left {
display: none; }
#toggle-left:checked ~ .page-wrap nav.menu {
left: 0px; }
#toggle-left:checked ~ .page-wrap .menu-toggle {
left: 220px; }
.profile-toggle {
text-decoration: none;
text-align: center;
width: 44px;
height: 44px;
font-size: 30px;
color: rgba(0, 0, 0, 0.5);
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
position: absolute;
top: 0px;
right: 40px;
bottom: 0;
left: auto;
z-index: 2; }
.profile-toggle:hover {
color: #000000; }
#toggle-right {
display: none; }
#toggle-right:checked + .page-wrap nav.profile {
right: 0px; }
#toggle-right:checked + .page-wrap .profile-toggle {
right: 220px; }
nav.menu {
position: fixed;
top: 0px;
right: auto;
bottom: 0px;
left: -270px;
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
height: auto;
width: 200px;
background: #111111;
z-index: 2000; }
nav.profile {
position: fixed;
top: 0px;
right: -270px;
bottom: 0px;
left: auto;
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
height: auto;
width: 200px;
background: #990000;
z-index: 2000; }
<input type="checkbox" id="toggle-left">
<input type="checkbox" id="toggle-right">
<div class="page-wrap">
<header>
<div class="top-bar">
<label for="toggle-left" class="menu-toggle">☰</label>
<label for="toggle-right" class="profile-toggle"><b>+</b></label>
</div>
<div class="middle-line"></div>
<div class="bottom-bar"></div>
</header>
<nav class="menu">
</nav>
<nav class="profile">
</nav>