I am trying to style a group of radio buttons and also have the animation work. You will see if I delete the <div> with class="group55" from the code, then the animation works just fine. When I add that element back in, it seems like the CSS I have is not being recognized any longer. What am I doing wrong? The ultimate goal would be to have the "group55" <div> surround the group of radio buttons and still have the animation keep working.
.toggle1:checked ~ .panel1 {
left: 0px;
}
.panel1 {
transition:all 500ms ease;
width: 300px;
height: 100px;
border: 1px solid black;
position: absolute;
left: -300px;
}
<div class="group55">
<input type="radio" class="toggle1" id="toggle1" name="group" checked/>
<input type="radio" class="toggle2" id="toggle2" name="group" />
<div class="panel1">
panels 1
</div>
(Also available at jsFiddle.)
This not work because you need to put the panel as sibling of the input, to make the sibling selector (~) work.
Fix HTML:
<div class="group55">
<input type="radio" class="toggle1" id="toggle1" name="group" checked />
<input type="radio" class="toggle2" id="toggle2" name="group" />
<div class="panel1">
panels 1
</div>
</div>
Check: https://jsfiddle.net/lmgonzalves/85f57nd8/1/
If you try to add the "group55" surround the group of radio buttons,your animation will not work.Click here to see you code again the code that you wish to do
Because the class ".toggle1:checked ~ .panel1" will only work when the ".toggle1" is checked and both ".toggle1" class and ".panel1" class must have inside the "group55" like this.....
<div class="group55">
<input type="radio" class="toggle1" id="toggle1" name="group" checked />
<input type="radio" class="toggle2" id="toggle2" name="group" />
<div class="panel1">
panels 1
</div>
</div>
Click here to see the answer with another way
Something i also did was setting the left property of your panel 1 class to 4px and it worked, because in css properties like left and right work in opposite way so when you said left -300px it's actually the left but normally it ought to go right. Check http://jsfiddle.net/85f57nd8/4/
.toggle1:checked ~ .panel1 {
left: 0px;
}
.panel1 {
transition:all 500ms ease;
width: 300px;
height: 100px;
border: 1px solid black;
position: absolute;
left: 4px;
}
Related
Edit: The original answer did not work for mobile devices. Go here for a solution that does.
I already know how to make an <input type="radio">'s <label> look like the button of any specific browser's default <button> by playing with the CSS until it looks identical to the <button> I'm trying to replicate. But this will look out of place whenever someone views it from a browser that has a different default <button>. (Even if I could replicate every default <button> for every browser, a new one will probably be invented tomorrow.)
Therefore, I want to use an actual button to get the default styling appropriate to the browser.
A recreation of the code so far:
<h1>Choose A or B</h1>
<label><button type="button"><input type="radio" name="choice" value="A">A</button></label>
<label><button type="button"><input type="radio" name="choice" value="B">B</button></label>
Later I'll change <input type="radio" name="choice" value="A"> to <input type="radio" name="choice" value="A" hidden> and use some other styling to show if it's checked or not, but for now I'm leaving it in for diagnostic reasons.
If you run the snippet, you'll notice that clicking the <input type="radio"> works as intended, but clicking the <button>itself does nothing.
Here is another failed attempt:
<h1>Choose A or B</h1>
<input type="radio" name="choice" value="A" id="a"><label for="a"><button type="button">A</button></label>
<input type="radio" name="choice" value="B" id="b"><label for="b"><button type="button">B</button></label>
I even tried adding the disabled attribute. Nothing is working as intended. Should I give up and style the <label> manually, or is there a way to access <button>'s default appearance anyway?
(Yes, I already know I could use javascript to simulate <input type="radio">'s behaviour on a <button> but I'm going to have lots of buttons in lots of groups throughout the website. So I'll just style <label> manually if it means the website will be easier to maintain. Likewise for installing an entire library just for this one problem.)
An idea is to add pointer-events:none; to the button but you won't have the styles of the :focus,:active and :hover state.
button {
pointer-events:none;
}
<h1>Choose A or B</h1>
<input type="radio" name="choice" value="A" id="a"><label for="a"><button type="button">A</button></label>
<input type="radio" name="choice" value="B" id="b"><label for="b"><button type="button">B</button></label>
You can, however, add your own custom :focus :active :hover and :checked state with:
input[type="radio"]:focus + label button{
/*add checked style here*/
label:hover > button {
/*add hover style here*/
}
label:active > button {
/*add active style here*/
}
input[type="radio"]:checked + label button{
/*add checked style here*/
It will not work, as you are doing. You need to do it like this.
[type="radio"]:checked,
[type="radio"]:not(:checked) {
position: absolute;
left: -9999px;
}
[type="radio"]:checked + label,
[type="radio"]:not(:checked) + label
{
position: relative;
padding-left: 28px;
cursor: pointer;
line-height: 20px;
display: inline-block;
color: #666;
}
[type="radio"]:checked + label:before,
[type="radio"]:not(:checked) + label:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 30px;
border: 1px solid #ddd;
border-radius: 5px;
background: #fff;
z-index: -1;
}
[type="radio"]:checked + label:after,
[type="radio"]:not(:checked) + label:after {
content: '';
width: 94px;
height: 24px;
background: #F87DA9;
position: absolute;
top: 4px;
left: 4px;
border-radius: 5px;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
z-index: -1;
}
[type="radio"]:not(:checked) + label:after {
opacity: 0;
-webkit-transform: scale(0);
transform: scale(0);
}
[type="radio"]:checked + label:after {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
<form action="#">
<p>
<input type="radio" id="test1" name="radio-group" checked>
<label for="test1">Apple</label>
</p>
<p>
<input type="radio" id="test2" name="radio-group">
<label for="test2">Peach</label>
</p>
<p>
<input type="radio" id="test3" name="radio-group">
<label for="test3">Orange</label>
</p>
</form>
You can do it using CSS :before and :after pseudo-classes without using any button. You can modify the above example as per your requirements.
Code is copied from https://codepen.io/manabox/pen/raQmpL and is used after modifications in the above example.
I been looking for this problem over the internet but I cant seem to find one that fix all of if, I have a parent div that centers all elements, but would not center the check box (only in safari) I tried moving it about using different methods such as margin, left/right etc etc, but nothing makes that little bastard move from its original place. Neither does the width/height works.
.right-content{
position: fixed;
right: 0;
bottom: 0;
height: 0;
width: 300px;
overflow-y: hidden;
transition: 0.5s;
background-color: #DC0000;
text-align: center;
}
.right-content a {
padding: 3px 3px 3px 3px;
text-decoration: none;
color: black;
display: block;
transition: 0.3s;
}
<div id="sidebarMort" class="right-content">
×
<a style="margin-top: 50px"><h2>Mortgage Calculator</h2></a>
<a><input name="income" type="text" id="income" placeholder="Annual Income"></a><br>
<p>Are you First Time Buyer?</p><br>
<a>Yes<input type="checkbox" id="ftb" value="ftb"></a><br>
<a><p>No</p><input type="checkbox" id="stb" value="stb"></a>
<a><input type="submit" class="btnOnBar" value="Calculate"></a>
</div>
#Luke i don't think that there is need to put Input inside anchor tag. Please update your code first. here is the updated code please check. Ypu can use label instead of anchor tag . Rest you can update visual as per your requirement using css.
<div id="sidebarMort" class="right-content">
×
<a style="margin-top: 50px"><h2>Mortgage Calculator</h2></a>
<a><input name="income" type="text" id="income" placeholder="Annual Income"></a><br>
<p>Are you First Time Buyer?</p><br>
<label for="ftb">Yes<input type="checkbox" id="ftb" value="ftb"></label>
<label for="stb">No<input type="checkbox" id="stb" value="stb"></label>
<input type="submit" class="btnOnBar" value="Calculate">
</div>
I'm trying to get a garish red border around some radio buttons, but it is not showing up in Firefox latest or Chrome latest. Work fine in IE9/IE8.
Each of the input element on my form that are required has a data-val-required attribute put in by MVC3. All browsers puts in the red borders just dandy when we have a text or textarea inputs, but am struggling with the radio button. For IE, it works, but other browsers won't put the red border around it.
css:
input[data-val-required], select[data-val-required], textarea[data-val-required]
{
background-color: #F0FFFF;
border: 1px solid red;
}
view-source:
<label for="WaiveSelect">Do you waive confidentiality?</label><br />
<input data-val="true" data-val-number="The field WaiveSelect must be a number." data-val-required="Please select waive." id="WaiveSelect" name="WaiveSelect" type="radio" value="0" /> No, I do not waive confidentiality<br />
<input id="WaiveSelect_2" name="WaiveSelect" type="radio" value="2" /> Yes, I waive confidentiality<br />
<input id="WaiveSelect_3" name="WaiveSelect" type="radio" value="3" /> Yes, I waive confidentiality except to the client<br />
<span class="field-validation-valid" data-valmsg-for="WaiveSelect" data-valmsg-replace="true"></span>
What it looks like in IE (Firefox and Chrome shows no borders):
input[type=radio]{
outline: 1px solid red
}
I know this is four years old, but I came up with a nice solution using CSS Pseudo elements.
My requirement was to highlight an unchecked checkbox, or radio button in validation.
<input type="radio" class="required" name="radio1"/>
/* Radio button and Checkbox .required needs an after to show */
input[type=radio].required::after, input[type=checkbox].required::after {
display: block;
width: 100%;
height: 100%;
background: transparent;
content: '';
border: 2px solid red !important;
box-sizing: border-box;
}
/* Radio buttons are round, so add 100% border radius. */
input[type=radio].required::after {
border-radius:100%;
}
You could accomplish by wrapping each input element with div tag and give it a border and a float left... like this:
<div style="border:1px solid red;float:left">
<input type="radio".. />
</div>
No, I do not waive confidentiality
Not all browsers support borders around radio buttons and checkboxes. I voted for a bug years ago to have this included in Gecko but so far they haven't implemented it.
This may help you:
.style {
border: 1px solid red;
width: 20px;
height: 20px;
text-align: center;
margin-top: 2px;
background-color: #f0ffff;
}
<div class="style">
<input type="radio" />
</div>
<div class="style">
<input type="radio" />
</div>
<div class="style">
<input type="radio" />
</div>
<div class="style">
<input type="radio" />
</div>
View on JSFiddle
Complete code using jquery
https://jsfiddle.net/xcb26Lzx/
$(function(){
$('.layer').css('border',0);
$('input:radio').change(
function(){
if ($(this).is(':checked')) {
$('.layer').css('border','1px solid red');
}
});
});
Try this...
Put a div around the input and assign a class to the div like so:
<div class="custom"><input type="radio"></div>
Then open your custom css file and add this CSS
.custom {border: 1px solid red; border-radius: 30px; padding: 3px 3px 0 3px; background: red;}
This should create a nice red border around the radio button. If you're using a check box you would simply remove the border-radius: 30px from the css. Depending you may need to play with the padding a bit to center the button, but this worked for me.
Edit: You will also want to assign the following CSS to the div so it lines up correctly.
.custom {display: inline;}
fiddle link
I've seen some tricks to change the background color (or other css attributes) on a group of radio buttons. Here is some html
<div class="myclass col-xs-3">
<input type="radio" name="mygroup" value="one" data-bind="checked: SelectedAttributeValueId" />
</div>
<div class="myclass col-xs-3">
<input type="radio" name="mygroup" value="two" data-bind="checked: SelectedAttributeValueId" />
</div>
<div class="myclass col-xs-3">
<input type="radio" name="mygroup" value="three" data-bind="checked: SelectedAttributeValueId" />
</div>
I've tried things like:
.myclass input[type="radio"]:checked{
background-color:#f2f2f2;
}
and
.myclass :checked{
background-color:#f2f2f2;
}
here is a fiddle link. I am using knockout, so maybe this is the tool I should use to style the <div> elements?
All input is appreciated, I would prefer not to use jquery or javscript here (although knockout is okay)
It is not possible to style the radio buttons circle.
However, you can use pseudo-elements (in this case :before) to render a box around the radio button, then style it in CSS.
input[type="radio"] {
display: inline-block;
position: relative;
width: 25%;
margin: 0;
}
input[type="radio"]:before {
content: '';
position: absolute;
z-index: -1;
top: -.5em;
right: 0;
bottom: -.5em;
left: 0;
border: 1px solid black;
background-color: #0073ae;
}
input[type="radio"]:checked:before {
background-color: #f2f2f2;
}
<input type="radio" name="mygroup" value="one" /><input
type="radio" name="mygroup" value="two" /><input
type="radio" name="mygroup" value="three"/>
Here's a solution via jquery.
$('[type=radio]').click(function(){
if($(this).val() == "one") {
$('.myclass').css("background-color", "yellow");
}
//...two...three
});
i copied a checkbox code from codepen. it works perfectly after i change it to my preference but the problem is, the check box works if its one alone ( only one checks if its above one ). is there any way to make ecah of them work independently without changing the classes and id's each time i need it. FIDDLE HERE
HTML
<div class="roundedOne">
<input type="checkbox" value="None" id="roundedOne" name="check" />
<label for="roundedOne"></label>
</div>
<div class="roundedOne">
<input type="checkbox" value="None" id="roundedOne" name="check" />
<label for="roundedOne"></label>
</div>
<div class="roundedOne">
<input type="checkbox" value="None" id="roundedOne" name="check" />
<label for="roundedOne"></label>
</div>
<div class="roundedOne">
<input type="checkbox" value="None" id="roundedOne" name="check" />
<label for="roundedOne"></label>
</div>
CSS
.roundedOne {
width: 20px;
height: 20px;
position: relative;
background: #fcfff4;
border: 2px solid #77c100;
border-radius: 3px;
}
.roundedOne label:after {
content: '';
width: 14.5px;
height: 15px;
position: absolute;
top: 2px;
left: 2px;
background: #77c100;
opacity: 0;
border-radius: 3px;
}
.roundedOne label:hover::after {
opacity: 0.3;
}
.roundedOne input[type=checkbox] {
visibility: hidden;
}
.roundedOne input[type=checkbox]:checked + label:after {
opacity: 1;
}
All your checkboxes have the same ID. And your label's for="" are all pointing to the same id. Make them different and that should fix your issue. Your IDs have to be different. You can only have the one instance of a particular ID on a given page
You're issue is with having multiple uses of ID.
The:
<label for="roundedOne"></label>
is looking for an input with the id="roundedOne".
Since all of your inputs share that ID it will go to the first one.
Try adding a unique ID to each input, and changing the labels to match, and that should solve your issue.
Here's a fiddle of the above changes.