Accessibility issue, tabs not working for custom inputs - html

I'm having an issue where only the initial checked input buttons are accessible by tabs. The inputs are set to 0 for visibility, so it should work as far as I can tell. I also tried tab-index, but that did not do anything. What am I doing wrong?
Here is the code in CodePen
.mainColorWrap input[type="radio"],
.imageSizeInputWrapOuter input[type="radio"] {
opacity: 0;
position: relative;
width: 0;
margin: 0 3px 0 0;
}
.mainColorWrap label {
display: inline-block;
background-color: #fff;
padding: 3px;
border: 1px solid #fff;
border-radius: 50%;
width: 50px;
height: 50px;
}
.mainColorWrap label:hover,
.mainColorWrap label:focus,
.frontColorWrap label:hover,
.frontColorWrap label:focus {
background-color: #000;
}
.mainColorWrap input[type="radio"]:focus + label {
border: 1px solid #777;
}
.mainColorWrap input[type="radio"]:checked + label {
background-color: #fff;
border-color: #777;
}
.radioButtonInner {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
position: relative;
}
<div class="mainColorWrap">
<form>
<input type="radio" name="colorOption" id="redCheck" value="red" class="mainColorRadiogroup" checked="" tabindex="0">
<label for="redCheck">
<div class="radioButtonInner" style="background-color: #c10e21;"></div>
</label>
<input type="radio" name="colorOption" id="greenCheck" value="green" class="mainColorRadiogroup" tabindex="0">
<label for="greenCheck">
<div class="radioButtonInner" style="background-color: #0ec155;"></div>
</label>
</form>
</div>

Related

How to display radio buttons as <div>

I want to display my radio buttons as so that i can give style sheet and make div clickable.
here are my radio buttons.
and I want to show them like this.
div as radio
This is what I have tried but did not work.
HTML
<div class="radio-toolbar">
<table>
<tr>
<td><input type="radio" id="radioone" name="product" value="first">
<label for="radioone">50</label></td>
<td><input type="radio" id="radiotwo" name="product" value="second">
<label for="radiotwo">100</label></td>
<td><input type="radio" id="radiothree" name="product" value="third">
<label for="radiothree">500</label></td>
</div>
CSS
.radio-toolbar input[type='radio']:focus + label {
border: 2px thin blue;
}
.radio-toolbar input[type='radio']:checked + label {
background-color: #86b1f7;
border-color: #4c4;
color: white;
}
So how can I achive this
Small help will be appreciated.
Thanks in advance :)
I had do this before.and I have the code preperd.I hope It will be useful for you.
.switch-field {
display: flex;
overflow: hidden;
direction: ltr;
float: right;
text-align:right;
}
.switch-field input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-field label {
/*width: 33.33%;*/
background-color: transparent;
color: #666666;
font-size: 14px;
line-height: 1;
text-align: center;
padding: 10px 12px;
margin-left: 0px;
/*margin-right: -1px;*/
border: 1px solid #ddd;
transition: all 0.1s ease-in-out;
}
.switch-field label:hover {
cursor: pointer;
}
.switch-field input:checked + label {
background-color: #F4F5F9;
box-shadow: none;
border-color: #3E7DE7;
color: #3E7DE7;
}
.switch-field label:first-of-type {
border-radius: 2px 0px 0px 2px;
}
.switch-field label:last-of-type {
border-radius: 0px 2px 2px 0px;
}
<div class="switch-field">
<input class="uk-radio" id="radio-six" type="radio" value="admin" name="user_type" checked>
<label for="radio-six">admin</label>
<input class="uk-radio" id="radio-seven" type="radio" value="user" name="user_type" >
<label for="radio-seven">user</label>
</div>
Here is one way you can customize your radio buttons.
.radio-toolbar .radio-item {
position: relative;
display: inline-block;
vertical-align: top;
margin: 15px 5px;
}
.radio-item input[type="radio"] {
position: absolute;
width: 0;
height: 0;
top: 0;
left: 0;
}
.radio-item label {
padding: 10px;
color: #fff;
border-radius: 10px;
background-color: grey;
border: 1px solid #000;
}
.radio-item input[type="radio"]:checked ~ label {
border-color: #f00;
}
<div class="radio-toolbar">
<div class="radio-item">
<input type="radio" id="radioone" name="product" value="first">
<label for="radioone">50</label>
</div>
<div class="radio-item">
<input type="radio" id="radiotwo" name="product" value="second">
<label for="radiotwo">100</label>
</div>
<div class="radio-item">
<input type="radio" id="radiothree" name="product" value="third">
<label for="radiothree">500</label>
</div>
</div>
Please let me know if this helps.
You need to hide the radio buttons and the left over label is still "clickable"
.radio-toolbar input[type="radio"] {
display: none;
}
I put all the working code on codepen here: https://codepen.io/stormingorman-the-vuer/pen/ExjKRvz
Try Like This. Make Your radio-toolbar input, width: 0;
also make your radio-toolbar label Like this
.radio-toolbar label {
background-color: #A9A9A9;
padding: 10px 20px;
font-size: 16px;
border-radius: 4px;
}

CSS Radio-button and text outline

I'm having a problem with setting up box & shadow around my radio button. My CSS sets box only around radio button and shows nasty white square box around it. How to set border or outline around whole Radio-button + text to make selection more distinctive.
enrgy-form {
width: 50%;
float: right;
}
.label-width {
margin-left: 22px;
white-space: nowrap;
}
.label-nowrapp {
white-space: nowrap;
}
.selected-item input:checked {
/*border: 1px solid dodgerblue;*/
box-shadow: 3px 3px 11px 1px dodgerblue;
}
<div class="form-check enrgy-form">
<label class="form-check-label label-nowrapp selected-item">
<input class="form-check-input selected-item" type="radio" name="energy" formControlName="energy" value="Energy" (change)="setOptions()">Fuel-fired</label>
</div>
I think your best bet is to simulate the radio button with css so you can have the behavior you want.
You should first set the input to display: none and give it an id in your HTML so you can link it with the label, by giving the label a for attribute, this way you can control the check/uncheck of your radio button from the label.
Next you want to simulate the appearance of the radio button, i'll do this by adding two spans, one inside the other, so we can have a checked/unchecked status.
try this:
enrgy-form {
width: 50%;
float: right;
}
.label-width {
margin-left: 22px;
white-space: nowrap;
}
.label-nowrapp {
white-space: nowrap;
}
.selected-item {
display: none;
}
.selected-item:checked + label {
box-shadow: 0px 0px 11px 2px dodgerblue;
}
label{
padding: 3px;
}
label .bullet{
border-radius: 50%;
border: 1px solid gray;
background-color: lightgray;
margin-right: 3px;
display: inline-block;
width: 10px;
height: 10px;
position: relative;
}
.selected-item:checked + label .bullet .bullet-selected{
position: absolute;
top: 50%;
left: 50%;
border-radius: 50%;
transform: translate(-50%, -50%);
display: inline-block;
width: 5px;
height: 5px;
background-color: gray;
}
<div class="form-check enrgy-form">
<input class="form-check-input selected-item" type="radio" name="energy" formControlName="energy" value="Energy" (change)="setOptions()" id="someUniqueId"/>
<label class="form-check-label label-nowrapp" for="someUniqueId">
<span class="bullet">
<span class="bullet-selected"></span>
</span>
Fuel-fired
</label>
</div>
You could go the route where you style the whole radio button using :before and :after in CSS. That way you could even go nuts with animations and stuff...
It would require you to change the HTML a bit as well....
There's plenty of examples to be found if you search for "css custom radio".
[type="radio"]{
position: absolute;
left: -9999px;
}
[type="radio"] + label
{
position: relative;
padding: 0 20px;
cursor: pointer;
}
[type="radio"] + label:before{
content: '';
position: absolute;
left: 0;
top: 0;
width: 14px;
height: 14px;
border: 1px solid #ddd;
border-radius: 100%;
background: #fff;
}
[type="radio"]:checked + label:before{
box-shadow: 0px 1px 11px 1px dodgerblue;
}
[type="radio"] + label:after{
content: '';
display: none;
width: 10px;
height: 10px;
background: gray;
position: absolute;
top: 3px;
left: 3px;
border-radius: 100%;
}
[type="radio"]:checked + label:after {
display: block;
}
<div class="form-check enrgy-form">
<input type="radio" name="energy" id="one">
<label for="one">Fuel-fired</label>
</input>
<input type="radio" name="energy" id="two">
<label for="two">Something else</label>
</input>
</div>
Update
Here is a possible solution, you could modify it as you want!
.form-check {
position: relative;
display: inline-flex;
align-items: center;
font-size: 1rem;
}
.form-check-label {
font-size: 0.9em;
margin-right: 0.25em;
white-space: nowrap;
}
.form-check-input {
margin: 0;
margin-right: 0.5em;
}
.form-check-input:checked + .form-check-label:after {
content: '';
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
border-radius: 1.5em 8px 8px 1.5em;
box-shadow: 3px 3px 11px 1px dodgerblue;
}
.medium { font-size: 2rem; }
.medium input[type=radio] { zoom: 2 }
.big { font-size: 3rem; }
.big input[type=radio] { zoom: 3 }
<div class="form-check">
<input id="inputcheck" class="form-check-input" type="radio" name="energy" formControlName="energy" value="Energy">
<label for="inputcheck" class="form-check-label">Fuel-fired normal</label>
</div>
<br><br>
<div class="form-check medium">
<input id="inputcheck1" class="form-check-input" type="radio" name="energy" formControlName="energy" value="Energy">
<label for="inputcheck1" class="form-check-label">Fuel-fired medium</label>
</div>
<br><br>
<div class="form-check big">
<input id="inputcheck2" class="form-check-input" type="radio" name="energy" formControlName="energy" value="Energy">
<label for="inputcheck2" class="form-check-label">Fuel-fired big</label>
</div>

Custom slider on css: problems with checked property

I want to make custom slider on css. Here is its code:
.slider input[type=radio] {
display: none;
}
.slider__slider-controls {
margin-bottom: 10px;
text-align: center;
}
.slider__slider-controls label {
display: inline-block;
width: 5px;
height: 5px;
margin-top: 0;
margin-left: 0;
margin-right: 16px;
background-color: #bec2c7;
border-radius: 50%;
transition: background-color 0.2s;
cursor: pointer;
}
.radio-slider__one:checked ~ .radio-slider-1 {
border: 3px solid #000000;
width: 6px;
height: 6px;
background-color: #white;
}
.radio-slider__two:checked ~ .radio-slider-2 {
border: 3px solid #000000;
width: 6px;
height: 6px;
background-color: #white;
}
.radio-slider__three:checked ~ .radio-slider-3 {
border: 3px solid #000000;
width: 6px;
height: 6px;
background-color: #white;
}
<div class="slider">
<input type="radio" id="radio-slider-1" class="radio-slider radio-slider__one" checked>
<input type="radio" id="radio-slider-2" class="radio-slider radio-slider__two">
<input type="radio" id="radio-slider-3" class="radio-slider radio-slider__three">
<div class="slider__slider-controls">
<label for="radio-slider-1" class="radio-slider-1"></label>
<label for="radio-slider-2" class="radio-slider-2"></label>
<label for="radio-slider-3" class="radio-slider-3"></label>
</div>
If I understand this property right it will make action on .radio-slider-1 only when .radio-slider__one in checked state. But it doesn't work. What I am doing wrong?
There are a couple things going on here.
.radio-slider__three:checked ~ .radio-slider-3 is saying:
When .radio-slider__three is checked, find a sibling of class .radio-slider-3 and apply these styles. In your html .radio-slider-3 is not a sibling, but rather a child of a sibling. So to fix this you should change the selectors to be .radio-slider__one:checked ~ .slider__slider-controls .radio-slider-1
The next thing is that your radio elements have no name attribute, so when you "check" one you can uncheck it because you aren't selecting a different option. If you give them the same name attribute (slider in my example) they will only have 1 selected at a time.
.slider input[type=radio] {
display: none;
}
.slider__slider-controls {
margin-bottom: 10px;
text-align: center;
}
.slider__slider-controls label {
display: inline-block;
width: 5px;
height: 5px;
margin-top: 0;
margin-left: 0;
margin-right: 16px;
background-color: #bec2c7;
border-radius: 50%;
transition: background-color 0.2s;
cursor: pointer;
}
.radio-slider__one:checked ~ .slider__slider-controls .radio-slider-1 {
border: 3px solid #000000;
width: 6px;
height: 6px;
background-color: white;
}
.radio-slider__two:checked ~ .slider__slider-controls .radio-slider-2 {
border: 3px solid #000000;
width: 6px;
height: 6px;
background-color: white;
}
.radio-slider__three:checked ~ .slider__slider-controls .radio-slider-3 {
border: 3px solid #000000;
width: 6px;
height: 6px;
background-color: white;
}
<div class="slider">
<input name="slider" type="radio" id="radio-slider-1" class="radio-slider radio-slider__one" checked>
<input name="slider" type="radio" id="radio-slider-2" class="radio-slider radio-slider__two">
<input name="slider" type="radio" id="radio-slider-3" class="radio-slider radio-slider__three">
<div class="slider__slider-controls">
<label for="radio-slider-1" class="radio-slider-1"></label>
<label for="radio-slider-2" class="radio-slider-2"></label>
<label for="radio-slider-3" class="radio-slider-3"></label>
</div>
JSFiddle
Your HTML structure is wrong for the ~ selector. For A ~ B, it finds B matches following A at the same current level, not descendants.
Pull your labels out of the <div>, or add the div just after the ~ so it becomes part of the "following sibling" selection.
.radio-slider__one:checked ~ .slider__slider-controls > .radio-slider-1

CSS - Change parent div background-color on input check

.chk-circle {
width: 8px;
height: 8px;
background: #afb0b5;
border-radius: 100%;
position: relative;
float: left;
margin-top: 4px;
margin-right: 8px;
}
.chk-circle label {
display: block;
width: 4px;
height: 4px;
border-radius: 100px;
cursor: pointer;
position: absolute;
top: 2px;
left: 2px;
z-index: 1;
background: #fff;
}
.chk-hide {
visibility: hidden;
}
.chk-circle input[type=checkbox]:checked + label {
background: #63a70a;
}
<div class="chk-circle">
<input class="chk-hide" type="checkbox" id="chk1"/>
<label for="chk1"></label>
</div>
Which produces the following:
What I want to do is have the outer circle turn green when the input is checked, I have tried the following but the reverse happens:
Try this:
Apply with border property :
Updated
I was added the i for bullet creation.If you need increase the bullet size increase the width & height of I tag.And also added text in label. Both condition are working
.chk-circle input[type=checkbox]:checked + i {
top:0;
left:0;
border:2px solid green;
}
.chk-circle > i {
position:relative;
float:left;
display: block;
width: 6px;
height: 6px;
margin-top:5px ;
border-radius: 100px;
cursor: pointer;
z-index: 1;
border:3px solid #ddd;
background: #fff;
cursor:pointer;
}
.chk-circle > label{
cursor:pointer;
margin:0 10px auto;
}
.chk-hide {
visibility: hidden;
}
.chk-circle > input[type=checkbox]:checked + i{
border:3px solid green;
}
<div class="chk-circle">
<label for="chk1">some 1</label>
<input class="chk-hide" type="checkbox" id="chk1"/>
<i></i>
</div>
<div class="chk-circle">
<label for="chk2">some 2</label>
<input class="chk-hide" type="checkbox" id="chk2"/>
<i></i>
</div>
<div class="chk-circle">
<label for="chk3">some 3</label>
<input class="chk-hide" type="checkbox" id="chk3"/>
<i></i>
</div>
Try border-color property:
.chk-circle input[type=checkbox]:checked + label {
border-style: solid;
border-color: #0f0;
}
div {
background: pink;
width: 50px;
height:50px;
}
input[type=checkbox]:checked+div{
background: green;
}
input[type=checkbox]:checked + div p {
background: blue;
}
<input type="checkbox" checked>
<div>
<p>Test</p>
</div>
if you can change the structure of your html:
<input class="chk-hide" type="checkbox" id="chk1"/>
<div class="chk-circle">
<label for="chk1"></label>
</div>
you can do it like this:
.chk-hide[type=checkbox]:checked +.chk-circle {background: green;}
Example

Radiobutton styling with css

I am trying to style my Radio button with CSS. When the button is unchecked it should have a black border and and when its checked the circle should be completely black. Sadly my Code doesn't work.
My Code:
<div class="radioss">
<input type="radio" id="mann" name="selector">
<label for="mann">Mann</label>
</div>
<div class="radios">
<input type="radio" id="mann" name="selector">
<label for="mann">Frau</label>
</div>
.radioss{
float:left;
}
.radios{
float:left;
}
/*Radiobutton*/
input[type="radio"] {
display:none;
}
.mann:not(checked) + label:before{
content:" ";
display: inline-block;
border: 2px solid black;
width: 13px;
height:13px;
border-radius:7px;
}
.mann:checked + label:before{
background-color:black;
}
Does somebody have any idea what i am doing wrong?
You cannot use same or single ID for more than one elements, It won't work.
.radioss input[type=radio] {
display: none;
}
.radioss input[type=radio]:not(:checked) + label:before {
content: "";
border: 2px solid #000;
height: 10px;
width: 10px;
display: inline-block;
border-radius:7px;
}
.radioss input[type=radio]:checked + label:before {
content: "";
border: 2px solid #000;
height: 10px;
width: 10px;
background: #000;
display: inline-block;
border-radius:7px;
}
<div class="radioss">
<input type="radio" id="mann" name="selector">
<label for="mann">Mann</label>
<input type="radio" id="mann1" name="selector">
<label for="mann1">Frau</label>
</div>
Source: Checkbox styling only css
You can check the following link
its may help you.
.checkbox-form .lg-label:before {
content: '';
width: 18px;
height: 18px;
background-color: transparent;
margin-right: 10px;
margin-top: 5px;
border-radius: 50%;
border: 1px solid #afaeae;
}
input[type=checkbox]:checked + .lg-item-radio .checkbox-form .lg-label:before {
border-color: rgba(27, 205, 128, 0.6);
}
https://codepen.io/sifulislam/pen/dZvXjK