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;
}
Related
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>
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>
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
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
The heading pretty much explains it. I have a couple of checkboxes inside a scrollable div. But for some reasons the 'background-color' attribute doesn't work. Although the 'margin-top' does seem to work...
Just puzzling me how one attribute can work and another not. It's also not like the div has it's own set of background color attributes that could potentially over ride the checkboxes attributes.
Anyways, below is my HTML (which is generated by JSP):
<div class="listContainer">
<input type="checkbox" class="oddRow">item1<br/>
<input type="checkbox" class="evenRow">item2<br/>
<input type="checkbox" class="oddRow">item3<br/>
<input type="checkbox" class="evenRow">item4<br/>
...
</div>
And here is my CSS:
.listContainer {
border:2px solid #ccc;
width:340px;
height: 225px;
overflow-y: scroll;
margin-top: 20px;
padding-left: 10px;
}
.oddRow {
margin-top: 5px;
background-color: #ffffff;
}
.evenRow{
margin-top: 5px;
background-color: #9FFF9D;
}
A checkbox does not have background color.
But to add the effect, you may wrap each checkbox with a div that has color:
<div class="evenRow">
<input type="checkbox" />
</div>
<div class="oddRow">
<input type="checkbox" />
</div>
<div class="evenRow">
<input type="checkbox" />
</div>
<div class="oddRow">
<input type="checkbox" />
</div>
In addition to the currently accepted answer: You can set border and background of a checkbox/radiobutton, but how it is rendered in the end depends on the browser. For example, if you set a red background on a checkbox
IE will show a red border instead
Opera will show a red background as intended
Firefox, Safari and Chrome will do nothing
This German language article compares a few browsers and explains at least the IE behavior. It maybe bit older (still including Netscape), but when you test around you'll notice that not much has changed. Another comparison can be found here.
You can use peseudo elements like this:
input[type=checkbox] {
width: 30px;
height: 30px;
margin-right: 8px;
cursor: pointer;
font-size: 27px;
}
input[type=checkbox]:after {
content: " ";
background-color: #9FFF9D;
display: inline-block;
visibility: visible;
}
input[type=checkbox]:checked:after {
content: "\2714";
}
<label>Checkbox label
<input type="checkbox">
</label>
After so much trouble i got it.
.purple_checkbox:after {
content: " ";
background-color: #5C2799;
display: inline-block;
visibility: visible;
}
.purple_checkbox:checked:after {
content: "\2714";
box-shadow: 0px 2px 4px rgba(155, 155, 155, 0.15);
border-radius: 3px;
height: 12px;
display: block;
width: 12px;
text-align: center;
font-size: 9px;
color: white;
}
<input type="checkbox" class="purple_checkbox">
It will be like this when checked with this code.
My solution
Initially posted here.
input[type="checkbox"] {
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
background: lightgray;
height: 16px;
width: 16px;
border: 1px solid white;
}
input[type="checkbox"]:checked {
background: #2aa1c0;
}
input[type="checkbox"]:hover {
filter: brightness(90%);
}
input[type="checkbox"]:disabled {
background: #e6e6e6;
opacity: 0.6;
pointer-events: none;
}
input[type="checkbox"]:after {
content: '';
position: relative;
left: 40%;
top: 20%;
width: 15%;
height: 40%;
border: solid #fff;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
display: none;
}
input[type="checkbox"]:checked:after {
display: block;
}
input[type="checkbox"]:disabled:after {
border-color: #7b7b7b;
}
<input type="checkbox"><br>
<input type="checkbox" checked><br>
<input type="checkbox" disabled><br>
<input type="checkbox" disabled checked><br>
2022 - there is a much better solution to this problem now
Just use the accent-color property and make sure you achieve proper contrast ratios for accessibility:
.blue-checkbox {
accent-color: #00eaff;
height: 30px; /* not needed */
width: 30px; /* not needed */
}
<input class="blue-checkbox" type="checkbox" />
We can provide background color from the css file. Try this one,
<!DOCTYPE html>
<html>
<head>
<style>
input[type="checkbox"] {
width: 25px;
height: 25px;
background: gray;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
outline: none;
position: relative;
left: -5px;
top: -5px;
cursor: pointer;
}
input[type="checkbox"]:checked {
background: blue;
}
.checkbox-container {
position: absolute;
display: inline-block;
margin: 20px;
width: 25px;
height: 25px;
overflow: hidden;
}
</style>
</head>
<body>
<div class="checkbox-container">
<input type="checkbox" />
</div>
</body>
</html>
The Best solution to change background checkbox color
input[type=checkbox] {
margin-right: 5px;
cursor: pointer;
font-size: 14px;
width: 15px;
height: 12px;
position: relative;
}
input[type=checkbox]:after {
position: absolute;
width: 10px;
height: 15px;
top: 0;
content: " ";
background-color: #ff0000;
color: #fff;
display: inline-block;
visibility: visible;
padding: 0px 3px;
border-radius: 3px;
}
input[type=checkbox]:checked:after {
content: "✓";
font-size: 12px;
}
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a bus<br>
Improving another answer here
input[type=checkbox] {
cursor: pointer;
margin-right: 10px;
}
input[type=checkbox]:after {
content: " ";
background-color: lightgray;
display: inline-block;
position: relative;
top: -4px;
width: 24px;
height: 24px;
margin-right: 10px;
}
input[type=checkbox]:checked:after {
content: "\00a0\2714";
}
When you input the body tag, press space just one time without closing the tag and input bgcolor="red", just for instance. Then choose a diff color for your font.