How to add an image to the back of a custom checkbox - css

I found a really clean looking custom checkbox on codepen and just updated a project to use it. Right now I've got the background colors different for the different sections of my form, but I'd like to just make background an icon rather than just a solid color
The commented out stuff doesn't work
.label-switch {
display: inline-block;
position: relative;
}
.label-switch::before,
.label-switch::after {
content: "";
display: inline-block;
cursor: pointer;
transition: all 0.5s;
}
.label-switch::before {
width: 3em;
height: 1em;
border: 1px solid #757575;
border-radius: 4em;
background: #888888;
}
.label-switch::after {
position: absolute;
left: 0;
top: -20%;
width: 1.5em;
height: 1.5em;
border: 1px solid #757575;
border-radius: 4em;
background: #ffffff;
}
.input-switch:checked~.label-switch::before {
background: #00a900;
border-color: #008e00;
}
.input-switch:checked~.label-switch::after {
left: unset;
right: 0;
background: #00ce00;
/*background-image:(url(http://pngimg.com/uploads/pokeball/pokeball_PNG8.png);*/
/*background: url(http://pngimg.com/uploads/pokeball/pokeball_PNG8.png);*/
border-color: #009a00;
}
<input class='input-switch' type="checkbox" id="demo" />
<label class="label-switch" for="demo"></label>
<span class="info-text"></span>

Everything you did was correct it's just the background image needed to have a background-position and background-size set if you toggle the checkbox in my snippet you should see the background pattern as you intended it to work.
.label-switch{
display: inline-block;
position: relative;
}
.label-switch::before, .label-switch::after{
content: "";
display: inline-block;
cursor: pointer;
transition: all 0.5s;
}
.label-switch::before {
width: 3em;
height: 1em;
border: 1px solid #757575;
border-radius: 4em;
background: #888888;
}
.label-switch::after {
position: absolute;
left: 0;
top: -20%;
width: 1.5em;
height: 1.5em;
border: 1px solid #757575;
border-radius: 4em;
background: #ffffff;
}
.input-switch:checked ~ .label-switch::before {
background: #00a900;
border-color: #008e00;
}
.input-switch:checked ~ .label-switch::after {
left: unset;
right: 0;
background: #00ce00;
background-image:url(http://pngimg.com/uploads/pokeball/pokeball_PNG8.png);
background-size:contain;
background-position:center;
border-color: #009a00;
}
<input class='input-switch' type="checkbox" id="demo"/>
<label class="label-switch" for="demo"></label>
<span class="info-text"></span>

Related

Text input - can't align text top or bottom, only center

folks! I'm trying to align the text inside a text form input to be next to the line at the bottom, but it doesn't quite concede, insisting on being center aligned.
I've put some vertical-align: bottom on different elements, but it didn't work (it's on the code below).
Here is the codepen: https://codepen.io/ironsand-sou-eu/pen/zYEmEdw
HTML:
<div class="form-input field">
<input type="text" name="my_input" id="my_input" value="I'd love to be a little closer to the line below! Can you help me?">
<label for="my_input" data-title="Just some label"></label>
</div>
CSS:
.form-input {
width: 100%;
background-color: transparent;
border-bottom: 1px green solid;
border-top: none;
border-right: none;
border-left: none;
}
.form-input::before {
content: '';
position: absolute;
background-color: green;
left: 0;
bottom: 0;
width: 0;
height: 2px;
transition: ease-out 300ms;
}
.form-input:hover::before {
width: 100%;
}
.form-input:focus-within::before {
width: 100%;
}
.form-input input {
border: none;
width: 100%;
}
.form-input input:focus-visible {
outline: none;
}
.field {
position: relative;
margin-bottom: 15px;
vertical-align: bottom;
}
.field label::before {
content: attr(title);
position: absolute;
top: 0;
left: 15px;
line-height: 40px;
font-size: 14px;
color: #777;
transition: 300ms all;
}
.field input {
width: 100%;
line-height: 40px;
padding: 0 8px;
box-sizing: border-box;
font-size: 14px;
color: green;
vertical-align: bottom;
}
Place this at the bottom of the CSS section:
input[type=text] {
height: 15px;
}

input[type=radio]:before radio sticking out

The rounded edge is just sticking out of the square or circle so if I give before a white background the radio edge is still slightly visible.
input[type=radio] {
box-sizing: border-box;
margin: 0;
padding: 0;
position: relative;
cursor: pointer;
}
input[type=radio]:before {
content: "";
display: block;
width: 16px;
height: 16px;
border: 2px solid grey;
border-radius: 50%;
/* background-color: white; */
position: absolute;
top: 0;
left: 0;
}
> <input type="radio" name="r" checked>
How can I hide the radio button completely using css before?
I think using visibility:hidden may help, please check below :
input[type=radio] {
box-sizing: border-box;
margin: 0;
padding: 0;
position: relative;
cursor: pointer;
visibility: hidden;
}
input[type=radio]:before {
content: "";
display: block;
width: 16px;
height: 16px;
border: 2px solid grey;
border-radius: 50%;
/* background-color: white; */
position: absolute;
top: 0;
left: 0;
visibility: visible;
}
input[type=radio]:checked:after {
content: "";
display: block;
width: 10px;
height: 10px;
/* border: 2px solid green; */
border-radius: 50%;
background-color: green;
position: absolute;
top: 5px;
left: 5px;
visibility: visible;
}
<input type="radio" name="r" checked>
Here I've tried another way to do this by adding a span. Give it a try.
.customRadio {
position: relative;
}
input[type="radio"] {
opacity: 0;
margin: 0 5px 0 0;
transition: all 0.2s ease 0s;
}
input[type="radio"] + .radioSpan {
background-color: transparent;
border: 1px solid #aaaaaa;
border-radius: 50%;
content: "";
height: 17px;
left: 0;
position: absolute;
top: 2px;
width: 17px;
transition: all 0.3s ease 0s;
}
input[type="radio"]:focus + .radioSpan,
input[type="radio"]:active + .radioSpan {
box-shadow: 0 3px 5px 0 rgba(56, 49, 132, 0.5) !important;
}
input[type="radio"]:checked + .radioSpan {
background-color: #408BF9;
border: 1px solid transparent;
}
input[type="radio"]:checked + .radioSpan::before {
background-color: #ffffff;
border-radius: 50%;
bottom: 0;
content: "";
height: 9px;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
width: 9px;
z-index: 1;
}
input[type="radio"] ~ .radioText {
display: inline-block;
font-family: 'Roboto', sans-serif;
margin-left: 5px;
text-transform: capitalize;
}
<label class="customRadio">
<input type="radio"name="reportType" value="unsigned-report"/>
<span class="radioSpan"></span>
<span class="radioText">UnSigned Report</span>
</label>
Kindly find following solution:
HTML:
<div class="radio">
<input type="radio" name="r" checked>
</div>
CSS:
.radio {
box-sizing: border-box;
margin: 0;
padding: 0;
position: relative;
cursor: pointer;
}
.radio::before {
content: "";
visibility: hidden; // option-1
/* opacity: 0; // option-2 */
/* display: none; //option-3 */
}

css vertical form steps indicator?

I'm trying to create a vertical form steps indicator using css.
I found this https://codepen.io/erwinquita/pen/ZWzVRE which works fine in the codepen but when I try to copy the code from there and use it in my html page, the green circles do not show up!
I even copied the code and pasted it in jsfiddle but the same issue accrued.
this is the code:
.wrapper {
width: 330px;
font-family: 'Helvetica';
font-size: 14px;
border: 1px solid #CCC;
}
.StepProgress {
position: relative;
padding-left: 45px;
list-style: none;
&::before {
display: inline-block;
content: '';
position: absolute;
top: 0;
left: 15px;
width: 10px;
height: 100%;
border-left: 2px solid #CCC;
}
&-item {
position: relative;
counter-increment: list;
&:not(:last-child) {
padding-bottom: 20px;
}
&::before {
display: inline-block;
content: '';
position: absolute;
left: -30px;
height: 100%;
width: 10px;
}
&::after {
content: '';
display: inline-block;
position: absolute;
top: 0;
left: -37px;
width: 12px;
height: 12px;
border: 2px solid #CCC;
border-radius: 50%;
background-color: #FFF;
}
&.is-done {
&::before {
border-left: 2px solid green;
}
&::after {
content: "✔";
font-size: 10px;
color: #FFF;
text-align: center;
border: 2px solid green;
background-color: green;
}
}
&.current {
&::before {
border-left: 2px solid green;
}
&::after {
content: counter(list);
padding-top: 1px;
width: 19px;
height: 18px;
top: -4px;
left: -40px;
font-size: 14px;
text-align: center;
color: green;
border: 2px solid green;
background-color: white;
}
}
}
strong {
display: block;
}
}
<div class="wrapper">
<ul class="StepProgress">
<li class="StepProgress-item is-done"><strong>Post a contest</strong></li>
<li class="StepProgress-item is-done"><strong>Award an entry</strong>
Got more entries that you love? Buy more entries anytime! Just hover on your favorite entry and click the Buy button
</li>
<li class="StepProgress-item current"><strong>Post a contest</strong></li>
<li class="StepProgress-item"><strong>Handover</strong></li>
<li class="StepProgress-item"><strong>Provide feedback</strong></li>
</ul>
</div>
I don't understand what I am missing.
could someone please advice on this issue?
In the codepen link you've provided, LESS CSS Preprocessor has been used. That's why you couldn't replicate the same code with jsfiddle or your local instance. Simply, the CSS isn't working in your case, you are viewing the plain html because when you use the css preprocessor, browser can't render it directly.
If you want this code to work in jsfiddle, then you have to select SCSS as the language in the dropdown menu named as css in the css box. Here's the link that shows it is working: https://jsfiddle.net/9k67r0eg/1/
And if you want to use it in your local browser, then you may want to compile it. Check it here: http://lesscss.org/
However, the LESS can be converted to pure css also. Here's the converted code which you can use directly:
.wrapper {
width: 330px;
font-family: 'Helvetica';
font-size: 14px;
border: 1px solid #CCC;
}
.StepProgress {
position: relative;
padding-left: 45px;
list-style: none;
}
.StepProgress::before {
display: inline-block;
content: '';
position: absolute;
top: 0;
left: 15px;
width: 10px;
height: 100%;
border-left: 2px solid #CCC;
}
.StepProgress-item {
position: relative;
counter-increment: list;
}
.StepProgress-item:not(:last-child) {
padding-bottom: 20px;
}
.StepProgress-item::before {
display: inline-block;
content: '';
position: absolute;
left: -30px;
height: 100%;
width: 10px;
}
.StepProgress-item::after {
content: '';
display: inline-block;
position: absolute;
top: 0;
left: -37px;
width: 12px;
height: 12px;
border: 2px solid #CCC;
border-radius: 50%;
background-color: #FFF;
}
.StepProgress-item.is-done::before {
border-left: 2px solid green;
}
.StepProgress-item.is-done::after {
content: "✔";
font-size: 10px;
color: #FFF;
text-align: center;
border: 2px solid green;
background-color: green;
}
.StepProgress-item.current::before {
border-left: 2px solid green;
}
.StepProgress-item.current::after {
content: counter(list);
padding-top: 1px;
width: 19px;
height: 18px;
top: -4px;
left: -40px;
font-size: 14px;
text-align: center;
color: green;
border: 2px solid green;
background-color: white;
}
.StepProgress strong {
display: block;
}
<div class="wrapper">
<ul class="StepProgress">
<li class="StepProgress-item is-done"><strong>Post a contest</strong></li>
<li class="StepProgress-item is-done"><strong>Award an entry</strong> Got more entries that you love? Buy more entries anytime! Just hover on your favorite entry and click the Buy button
</li>
<li class="StepProgress-item current"><strong>Post a contest</strong></li>
<li class="StepProgress-item"><strong>Handover</strong></li>
<li class="StepProgress-item"><strong>Provide feedback</strong></li>
</ul>
</div>

display text on toggle button

I have a simple checkbox toggle that change the background color when clicked or checked, that indicates active or not. My problem is I don't know how to put label on that button.
something like this.
I'm not sure if that possible.
I hope you understand me.
Thanks
CODEPEN
body{
background-color: #ddd;
}
.toggle {
-webkit-appearance: none;
appearance: none;
width: 65.57px;
padding: 10px;
height: 26.32px;
display: inline-block;
position: relative;
border-radius: 13px;
overflow: hidden;
line-height: 16px;
text-align: center;
font-size: 12px;
outline: none;
border: none;
cursor: pointer;
background: #E1F6FF;
transition: background-color ease 0.3s;
}
.toggle:before {
content: "text text";
display: block;
position: absolute;
z-index: 2;
width: 24px;
height: 24px;
background: #fff;
left: 0;
top: 0;
border-radius: 50%;
padding-top: 5px;
text-indent: -30px;
word-spacing: 37px;
color: #4D5585;
text-shadow: -1px -1px rgba(0,0,0,0.15);
white-space: nowrap;
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
transition: all cubic-bezier(0.3, 1.5, 0.7, 1) 0.3s;
}
.toggle:checked {
background: #dadce8;
}
.toggle:checked:before {
left: 40px;
}
.center{
text-align: center;
}
<div class="center">
<input class="toggle" type="checkbox" />
</center>
To achive desire result after edit, we are going to build something new.
HTML
<div class="switch">
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" checked>
<label class="switch-labels" for="myswitch">
<span class="switch-text"></span>
<span class="switch-dot"></span>
</label>
</div>
We will use a main div with class switch to build our switch. This will hold 2 things
The input so we can target it state and use both for styles and what i suppose future js styles
A label that will hold 2 things
2.1 The on and off text as before and after of a span
2.2 The white dot that slides on each state
CSS is commented on the snippet
Hope this is what you were looking for. Happy to explain or help in a better solution if needed.
body {
background-color: #ddd;
}
/*Style main div and remove default checkbox*/
.switch {
position: relative;
width: 75px;
margin: 0 auto;
}
.switch-checkbox {
display: none;
}
/*Style words and oval switch */
.switch-labels {
display: block;
overflow: hidden;
cursor: pointer;
border-radius: 20px;
}
.switch-text {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.switch-text:before,
.switch-text:after {
float: left;
width: 50%;
line-height: 30px;
color: white;
box-sizing: border-box;
}
.switch-text:before {
content: "ON";
padding-left: 10px;
background-color: #E1F6FF;
color: #000000;
}
.switch-text:after {
content: "OFF";
padding-right: 10px;
background-color: #4D5585;
color: #FFFFFF;
text-align: right;
}
/*Style center dot*/
.switch-dot {
width: 30px;
height: 30px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 41px;
margin-right: 5px;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.switch-dot:after{
content: "";
position: absolute;
width: 20px;
height: 20px;
background-size: cover;
background-image: url('http://www.free-icons-download.net/images/multiply-icon-27981.png');
margin: 5px 0 0 5px;
}
/*State changer*/
.switch-checkbox:checked+.switch-labels .switch-text {
margin-left: 0;
}
.switch-checkbox:checked+.switch-labels .switch-dot {
right: 0px;
margin-right: 0px;
}
<div class="switch">
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" checked>
<label class="switch-labels" for="myswitch">
<span class="switch-text"></span>
<span class="switch-dot"></span>
</label>
</div>
Change the text in content for toggle.before to
content: "hide show";
Well, just want to add labels?
use below inside .toggle:before
content: "Hide Show";
instead
content: "text text";
Thanks. Ask for more queries.
If you want to put the text on the white circle means , you can add this one in css
.toggle:before{
text-overflow: ellipsis;
overflow: hidden;
}
I am not sure if I understand your question right way. Do you mean add a lebal to toggle this checkbox?
body{
background-color: #ddd;
}
.toggle {
-webkit-appearance: none;
appearance: none;
width: 65.57px;
padding: 10px;
height: 26.32px;
display: inline-block;
position: relative;
border-radius: 13px;
overflow: hidden;
line-height: 16px;
text-align: center;
font-size: 12px;
outline: none;
border: none;
cursor: pointer;
background: #E1F6FF;
transition: background-color ease 0.3s;
}
.toggle:before {
content: "text text";
display: block;
position: absolute;
z-index: 2;
width: 24px;
height: 24px;
background: #fff;
left: 0;
top: 0;
border-radius: 50%;
padding-top: 5px;
text-indent: -30px;
word-spacing: 37px;
color: #4D5585;
text-shadow: -1px -1px rgba(0,0,0,0.15);
white-space: nowrap;
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
transition: all cubic-bezier(0.3, 1.5, 0.7, 1) 0.3s;
}
.toggle:checked {
background: #dadce8;
}
.toggle:checked:before {
left: 40px;
}
.center{
text-align: center;
}
<div class="center">
<input id="sample" class="toggle" type="checkbox" />
<label for="sample">This is a sample</label>
</center>

HTML5 slider bar's thumb can't cover the track

I made a slider bar with html5 & css, like this.
function showValue(value) {
document.getElementById("range").innerHTML = value;
}
.c-zoombar {
-webkit-appearance: none;
background: none;
outline: none;
overflow: hidden;
width: 200px;
height: 20px;
}
.c-zoombar::-webkit-slider-thumb {
-webkit-appearance: none;
background: #5e6fd9;
border: 1px solid #fff;
border-radius: 50%;
height: 12px;
position: relative;
top: -5.5px;
transition: .2s;
width: 12px;
}
.c-zoombar::-webkit-slider-runnable-track {
background: transparent;
border: 1px solid #000;
border-radius: 2px;
cursor: pointer;
height: 3px;
width: 100%;
}
.c-zoombar:active::-webkit-slider-thumb {
height: 16px;
top: -8px;
width: 16px;
}
.c-zoombar::-webkit-slider-thumb:hover {
height: 16px;
top: -8px;
width: 16px;
}
<div>
<input type="range" value="0" class="c-zoombar" onInput="showValue(this.value)" />
</div>
<div>
<span id="range">0</span>
</div>
However, when I scroll the thumb to the most right/left, the thumb can't totally cover the track, as you can see in the following image.
What should I modify to make the thumb be able to cover the track when scrolling to the most right/left? Thank you.
I found the transform: scale() could do the part of trick (also scale transitioned more smoothly then width/height). is that 12px size is mandatory?
function showValue(value) {
document.getElementById("range").innerHTML = value;
}
.c-zoombar {
-webkit-appearance: none;
background: none;
outline: none;
overflow: visible;
width: 200px;
height: 20px;
}
.c-zoombar::-webkit-slider-thumb {
-webkit-appearance: none;
background: #5e6fd9;
border: 1px solid #fff;
border-radius: 50%;
height: 12px;
position: relative;
top: -5.5px;
transition: .2s;
width: 12px;
transform: scale(1.33);
}
.c-zoombar::-webkit-slider-runnable-track {
background: transparent;
border: 1px solid #000;
border-radius: 2px;
cursor: pointer;
height: 3px;
width: 100%;
}
.c-zoombar:active::-webkit-slider-thumb,
.c-zoombar::-webkit-slider-thumb:hover {
transform: scale(1.66);
}
<div class='wrap'>
<input type="range" value="0" class="c-zoombar" onInput="showValue(this.value)" />
</div>
<div>
<span id="range">0</span>
</div>

Resources