Html ccs custom radio button right to left - html

I have been created custom radio button right to left
i used code from w3school
custom radio button w3school
but it's not working as right to left
that's mean first circle of radio and next text
.radioContainer{
display: inline-block;
position: relative;
cursor: pointer;
font-family: sans-serif;
font-size: 22px;
user-select: none;
padding-left: 30px;
direction: rtl;
}
.radioContainer input {
display:none;
}
.radioContainer .circle{
display: inline-block;
width: 25px;
height: 25px;
background-color: #eee;
position: absolute;
left: 0;
top: 0;
border-radius: 50%;
}
.radioContainer:hover .circle{
background-color: #ccc;
}
.radioContainer input:checked + .circle{
background-color: #2196fc;
}
.radioContainer input:checked + .circle:after{
content: "";
width: 10px;
height: 10px;
background-color: white;
position: absolute;
border-radius: 50%;
left:50%;
top:50%;
transform: translate(-50%,-50%);
}
<label class="radioContainer">my text1
<input type="radio" name="radio">
<span class="circle"></span>
</label>
<br/>
<label class="radioContainer">my text2
<input type="radio" name="radio">
<span class="circle"></span>
</label>
I want to change direction of label or put all the radio buttons on to div and set direction of div from right to left, but it's not working

Change padding-left to padding-right in radioContainer class.
And also change left to right in .radioContainer .circle
Your final CSS must be like this:
.radioContainer{
display: inline-block;
position: relative;
cursor: pointer;
font-family: sans-serif;
font-size: 22px;
user-select: none;
padding-right: 30px;
direction: rtl;
}
.radioContainer input {
display:none;
}
.radioContainer .circle{
display: inline-block;
width: 25px;
height: 25px;
background-color: #eee;
position: absolute;
right: 0;
top: 0;
border-radius: 50%;
}
.radioContainer:hover .circle{
background-color: #ccc;
}
.radioContainer input:checked + .circle{
background-color: #2196fc;
}
.radioContainer input:checked + .circle:after{
content: "";
width: 10px;
height: 10px;
background-color: white;
position: absolute;
border-radius: 50%;
left:50%;
top:50%;
transform: translate(-50%,-50%);
}

Related

Custom checkbox : add cross icon on uncheck using css?

I've been searching a while here and there and can't seem to find a way to stylize the uncheck state of a checkbox. I can change the background to red, but I need to add a cross as well, is it possible in css?
Here is my code and thanks for any help
/* The customcheck */
.customcheck {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
right: 10px;
}
/* Hide the browser's default checkbox */
.customcheck input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: red;
border-radius: 5px;
}
/* On mouse-over, add a grey background color */
.customcheck:hover input~.checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
.customcheck input:checked~.checkmark {
background-color: #02cf32;
border-radius: 5px;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.customcheck input:checked~.checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.customcheck .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
input[type=checkbox] {
position: relative;
}
<label class="customcheck">
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
I have used :pseudo element to add a cross icon
.customcheck {
position: relative;
}
.customcheck input {
display: none;
}
.customcheck input~.checkmark {
background: #ee0b0b;
width: 25px;
display: inline-block;
position: relative;
height: 25px;
border-radius: 2px;
vertical-align:middle;
margin-right:10px;
}
.customcheck input~.checkmark:after,
.customcheck input~.checkmark:before {
content: '';
position: absolute;
width: 2px;
height: 16px;
background: #fff;
left: 12px;
top: 4px;
}
.customcheck input~.checkmark:after {
transform: rotate(-45deg);
z-index: 1;
}
.customcheck input~.checkmark:before {
transform: rotate(45deg);
z-index: 1;
}
.customcheck input:checked~.checkmark {
background: #3d8a00;
width: 25px;
display: inline-block;
position: relative;
height: 25px;
border-radius: 2px;
}
.customcheck input:checked~.checkmark:after {
display: none;
}
.customcheck input:checked~.checkmark:before {
background: none;
border: 2px solid #fff;
width: 6px;
top: 2px;
left: 9px;
border-top: 0;
border-left: 0;
height: 13px;
top: 2px;
}
<label class="customcheck">
<input type="checkbox" checked="checked">
<span class="checkmark"></span> Label Text
</label>
jep. Here is some quick code. You can always make it more beatiful. But this is the concept
<input class="customcheckInput" type="checkbox" checked="checked">
<label class="customcheck"></label>
.customcheck {
position: relative;
padding-left: 30px;
}
.customcheck:before {
content: "";
display: block;
position: relative;
border: 1px solid #000;
height: 20p;
width: 20px;
}
.customcheck:after {
content: "";
display: none;
position: absolute;
background: red;
height: 10p;
width: 10px;
left: 0;
top: 0;
}
.customcheckInput + .customcheck:after {
display: blocK;
}

Add image into custom checkbox

I've made custom checkbox, here is what i've made so far, but what I need is something like this, where there is also text and one image (not icon/fa-fa icon) in the center of the checkbox. Did u know how to achieve it? Here is the code from snippet:
div {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
height: 120px;
outline: 1px solid white;
width: 120px;
}
label:before {
background-color: red;
color: white;
display: block;
position: absolute;
width: 20px;
height: 20px;
top: 1px;
left: 1px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-ms-transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
outline: 1px solid red;
z-index: 99;
}
:checked + label img {
z-index: -1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
height: 95%;
width: 95%;
outline: 3px solid red;
}
<div>
<div>
<input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/103/103" /></label>
</div>
<div>
<input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/102/102" /></label>
</div>
</div>
Thanks in advance for your help.
You're doing just fine at your own. Your code looks a bit complex because you can use the label as a block-element (like a div or a wrapper). Take a step back, look at your layout 'inside' the checkbox and see it as a normal layout/styling element. Nothing fancy.
.styled {
/* could also be a background */
background-color: red;
padding: 1rem 4rem;
text-align: center;
cursor: pointer;
}
span {
display: block;
font-size: 16px;
font-family: Arial;
margin-top: 10px;
}
label {
display: block;
max-width: 100px;
margin: 0 auto;
}
#checkbox {
display: none;
}
input:checked+label {
background-color: green;
}
<input id="checkbox" type="checkbox">
<label class="styled" for="checkbox">
<img src="https://placehold.it/20x20" alt="image 1">
<img src="https://placehold.it/40x40" alt="image 2">
<img src="https://placehold.it/60x60" alt="image 3">
<span>Text</span>
</label>
<div>
<div><input type="checkbox" id="cb1" />
<label for="cb1">
<img src="http://lorempixel.com/103/103" />
<img src="https://dummyimage.com/120/000000/ffffff" />
<span>Text</span>
</label>
</div>
<div><input type="checkbox" id="cb2" />
<label for="cb2">
<img src="http://lorempixel.com/102/102" />
<img src="https://dummyimage.com/120/000000/ffffff" />
<span>Text</span>
</label>
</div>
</div>
div {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
height: 120px;
outline: 1px solid white;
width: 120px;
}
label:before {
background-color: red;
color: white;
display: block;
position: absolute;
width: 20px;
height: 20px;
top: 1px;
left: 1px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
z-index: 1;
}
label img + img {
height: 60%;
width: 60%;
z-index: 2;
position: absolute;
top: 10%;
left: 20%;
}
span {
z-index: 2;
color: red;
position: absolute;
top: 75%;
left: 40%;
text-align: center;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
outline: 1px solid red;
z-index: 3;
}
:checked + label img + img {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
height: 60%;
width: 60%;
outline: 0px solid transparent;
}
:checked + label img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 98%;
width: 98%;
outline: 3px solid red;
}

how to change the color of a checkmark when a link name is clicked

i have the following anchor tag thats embedded dynamically to a <ul> tag, when the user clicks on the word TEST i want the checkmark to change colour to blue,i tried the following but its not working,what am i doing wrong?
.checkmark{
display: inline-block;
width: 22px;
/* height: 22px; */
height: 17px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin-left: 50%;
margin-bottom: 1px;
}
.checkmark:before {
content: '';
position: absolute;
width: 3px;
height: 9px;
background-color: #ccc;
left: 11px;
top: 6px;
}
.checkmark {
cursor: pointer;
}
.checkmark:after {
content: '';
position: absolute;
width: 3px;
height: 3px;
background-color: #ccc;
left: 8px;
top: 12px;
}
input[type="checkbox"]:checked + .checkmark:before,
input[type="checkbox"]:checked + .checkmark:after {
background-color: blue;
}
<a class="internal" data-destination="local" dataid="66027" data-nodeid="undefined" ><span><input type="checkbox" style="display:none;" id="cb66027 "></span>TEST<label for="cb66027" class="checkmark"></label></a>
An <a> wrapped round an <input> will not toggle the checked state when clicked. You should convert the <a> to a <label>.
This means that your current .checkmark label will need to be a different element. I've used a span.
You should also move the <input> outside of it's parent <span> so that the <input> and .checkmark are siblings.
.checkmark {
display: inline-block;
width: 22px;
/* height: 22px; */
height: 17px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin-left: 50%;
margin-bottom: 1px;
}
.checkmark:before {
content: '';
position: absolute;
width: 3px;
height: 9px;
background-color: #ccc;
left: 11px;
top: 6px;
}
.checkmark {
cursor: pointer;
}
.checkmark:after {
content: '';
position: absolute;
width: 3px;
height: 3px;
background-color: #ccc;
left: 8px;
top: 12px;
}
input[type="checkbox"]:checked+.checkmark:before,
input[type="checkbox"]:checked+.checkmark:after {
background-color: blue;
}
<label class="internal" data-destination="local" dataid="66027" data-nodeid="undefined">
<input type="checkbox" style="display:none;" id="cb66027 ">
TEST
<span for="cb66027" class="checkmark"></span>
</label>
You are using a wrong + selector...
input+.checkmark means... input and .checkmark should be adjacent element...which is not in your case...
...so remove the span and put input and .checkmark in same level...
...also use opacity:0 instead of display:none to input[checkbox]...
I have changes some of your css
Stack Snippet
.checkmark {
display: inline-block;
width: 22px;
/* height: 22px; */
height: 17px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin-left: 50%;
margin-bottom: 1px;
}
.checkmark:before {
content: '';
position: absolute;
width: 3px;
height: 9px;
background-color: #ccc;
left: 11px;
top: 6px;
}
.checkmark {
cursor: pointer;
}
.checkmark:after {
content: '';
position: absolute;
width: 3px;
height: 3px;
background-color: #ccc;
left: 8px;
top: 12px;
}
input[type="checkbox"]:checked+.checkmark:before,
input[type="checkbox"]:checked+.checkmark:after {
background-color: blue;
}
input[type="checkbox"] {
position: absolute;
width: 100%;
left: 0;
z-index: 9;
height: 100%;
top: 0;
cursor: pointer;
opacity: 0;
margin: 0;
}
a.internal {
position: relative;
}
<a class="internal" data-destination="local" dataid="66027" data-nodeid="undefined" for="cb66027"><input type="checkbox" id="cb66027 ">TEST<label class="checkmark"></label></a>

CSS3 border-radius on toggle input not working in IE11

For some reason my toggle button styles are not working in IE11. The input button should be a green circle but it's showing as a square box with a quite background and black border in IE11:
Here is how it is intended to look:
My code:
.toggle-field {
position: relative;
padding-top: 0.35rem;
}
.toggle-field .Toggle {
padding-left: 75px;
}
.toggle-field .toggle-element {
position: absolute;
top: 0;
left: 0;
width: 68px;
height: 34px;
border-radius: 18px;
border: 2px solid #ccc;
}
.toggle-field input {
appearance: none;
display: block;
position: absolute;
left: 4px;
top: 4px;
width: 26px;
height: 26px;
background: #ccc;
border-radius: 15px;
transition: left 117ms ease;
border: none;
}
.toggle-field input:focus + .toggle-element {
border-color: #aaa;
}
.toggle-field b {
position: absolute;
font-weight: normal;
line-height: 34px;
top: 1px;
left: 40px;
font-size: 0.65rem;
}
.toggle-field .Toggle.On input {
left: 38px;
background: #2ea664;
}
.toggle-field .Toggle.On b {
left: 12px;
}
<div class="field toggle-field null">
<label for="button1" class="Toggle On">
<input type="checkbox" id="button1" name="button1" value="on">
<span class="toggle-element"></span>
<b>YES</b> Question goes here
</label>
</div>
Most of what I have read says that I need to have a certain compatibility tag included, which I have:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Not sure what else to do. Has anyone else had this issue before?
I found a different way of doing this that works in IE11.
.toggle-field {
position: relative;
padding-top: 0.35rem;
}
.toggle-field .Toggle {
padding-left: 80px;
}
.toggle-field input {
appearance: none;
display: block;
position: absolute;
left: 6px;
top: 4px;
width: 26px;
height: 26px;
background: #ccc;
border-radius: 15px;
transition: left 117ms ease;
border: none;
}
.toggle-field .toggle-element {
background-color: #fff;
border: 2px solid #ccc;
bottom: 0;
cursor: pointer;
left: 0;
position: absolute;
right: 0;
top: 0;
transition: .4s;
width: 68px;
height: 32px;
}
.toggle-element:before {
background-color: #ccc;
bottom: 3px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: .4s;
width: 26px;
}
input:checked + .toggle-element {
background-color: #fff;
}
input:checked + .toggle-element:before {
transform: translateX(34px);
background-color: #2ea664;
}
.toggle-element {
border-radius: 34px;
}
.toggle-element:before {
border-radius: 50%;
}
<div class="field toggle-field null">
<label for="checkbox" class="Toggle On">
<input type="checkbox" id="checkbox" />
<span class="toggle-element"></span>
</label>
</div>

Background Color Fill Animation Ends in Offset

I'm trying to "fill" a circle when a user clicks on it. The main issue is that when the animation ends, it's offset on the top by just a little bit. I've tried to add a margin-top: -1px to it but it's then offset on the bottom!
I'm open to any suggestion to make the animation smoother but my main question is: Why is the end result offset from the top a tiny bit and how can I fix it?
#searchOptions label {
display: inline-block;
cursor: pointer;
font-size: 14px;
text-transform: uppercase;
color: #000;
font-weight: 400;
margin-right: 40px;
}
#searchOptions label .circle {
display: inline-block;
position: relative;
border: 2px solid #000;
width: 15px;
height: 15px;
border-radius: 50%;
margin-right: 12px;
}
#searchOptions label .circle:before {
display: none;
position: absolute;
content: '';
background-color: #000;
border-radius: 50%;
top: 50%;
transform: translateY(-50%);
left: 0;
right: 0;
margin: 0 auto;
width: 2px;
height: 2px;
}
#searchOptions label .txt {
position: relative;
top: -3px;
}
#searchOptions input[type=radio] {
height: 0;
width: 0;
opacity: 0;
}
#searchOptions input[type=radio]:checked + label .circle:before {
display: block;
width: 100%;
height: 100%;
animation: fillRadio ease-in 1s;
}
#-webkit-keyframes fillRadio {
0% {
top: 50%;
transform: translateY(-50%);
width: 1%;
height: 1%;
}
100% {
top: 0%;
transform: translateY(0%);
width: 100%;
height: 100%;
}
}
<div id="searchOptions">
<input type="radio" name="searchType" value="option1" id="option1" />
<label for="option1"><span class="circle"></span> <span class="txt">Option 1</span>
</label>
<input type="radio" name="searchType" value="option2" id="option2" />
<label for="option2"><span class="circle"></span> <span class="txt">Option 2</span>
</label>
</div>
<!-- id="searchOptions" -->
Here's a JSFiddle if anyone would rather use that.
I believe that the problem comes from a dimensiion of 15px and top of 50% -> that gives a fractional size
I have changed the size to 16px, that is even:
#searchOptions label {
display: inline-block;
cursor: pointer;
font-size: 14px;
text-transform: uppercase;
color: #000;
font-weight: 400;
margin-right: 40px;
}
#searchOptions label .circle {
display: inline-block;
position: relative;
border: 2px solid #000;
width: 16px;
height: 16px;
border-radius: 50%;
margin-right: 12px;
}
#searchOptions label .circle:before {
display: none;
position: absolute;
content: '';
background-color: #000;
border-radius: 50%;
top: 50%;
transform: translateY(-50%);
left: 0;
right: 0;
margin: 0 auto;
width: 2px;
height: 2px;
}
#searchOptions label .txt {
position: relative;
top: -3px;
}
#searchOptions input[type=radio] {
height: 0;
width: 0;
opacity: 0;
}
#searchOptions input[type=radio]:checked + label .circle:before {
display: block;
width: 100%;
height: 100%;
animation: fillRadio ease-in 1s;
}
#-webkit-keyframes fillRadio {
0% {
top: 50%;
transform: translateY(-50%);
width: 1%;
height: 1%;
}
100% {
top: 0%;
transform: translateY(0%);
width: 100%;
height: 100%;
}
}
<div id="searchOptions">
<input type="radio" name="searchType" value="option1" id="option1" />
<label for="option1"><span class="circle"></span> <span class="txt">Option 1</span>
</label>
<input type="radio" name="searchType" value="option2" id="option2" />
<label for="option2"><span class="circle"></span> <span class="txt">Option 2</span>
</label>
</div>
<!-- id="searchOptions" -->