I can't select radio buttons after applying css - css

It defaults to the first one even after selecting other two.
My Code:-
input[type=radio] {
display:none;
}
input[type=radio] + label:before {
content: "";
display: inline-block;
width: 35px;
height: 35px;
vertical-align:middle;
margin-right: 8px;
background-color: #DFF0EF;
box-shadow: inset 0px 2px 2px rgba(0, 0, 0, .3);
border-radius: 4px;
}
input[type=radio]:checked + label:before {
content:"\2714";
color:white;
background-color: #34E098;
font-size:1.5em;
text-align:center;
line-height:34px;
text-shadow:0px 0px 3px #eee;
}
My Buttons:-
https://codepen.io/coderguyinthehouse/pen/VjbdLd

Your IDs need to be unique and so the associated labels' for value.
EG
<input type="radio" id="sizeselected1" name="downloadsize" value="KB">
<label for="sizeselected1">1</label>
input[type=radio] {
display:none;
}
input[type=radio] + label:before {
content: "";
display: inline-block;
width: 35px;
height: 35px;
vertical-align:middle;
margin-right: 8px;
background-color: #DFF0EF;
box-shadow: inset 0px 2px 2px rgba(0, 0, 0, .3);
border-radius: 4px;
}
input[type=radio]:checked + label:before {
content:"\2714";
color:white;
background-color: #34E098;
font-size:1.5em;
text-align:center;
line-height:34px;
text-shadow:0px 0px 3px #eee;
}
<form class="sizeselect" id="sizeselect" name="sizeselect">
<input type="radio" id="sizeselected1" name="downloadsize" value="KB"><label for="sizeselected1">1</label>
<input type="radio" id="sizeselected2" name="downloadsize" value="MB"><label for="sizeselected2">2</label>
<input type="radio" id="sizeselected3" name="downloadsize" value="GB"><label for="sizeselected3">3</label>
</form>
<form class="speedselect" id="speedselect" name="speedselect">
<input type="radio" id="speedselected1" name="downloadspeed" value="Kbps"><label for="speedselected1">11</label>
<input type="radio" id="speedselected2" name="downloadspeed" value="Mbps"> <label for="speedselected2">12</label>
<input type="radio" id="speedselected3" name="downloadspeed" value="Gbps"> <label for="speedselected3">13</label>
</form>

You can't use same ID's
<form class="sizeselect" id="sizeselect" name="sizeselect">
<input type="radio" id="sizeselected1" name="downloadsize" value="KB"
<label for="sizeselected1">1</label>
<input type="radio" id="sizeselected2" name="downloadsize" value="MB"
<label for="sizeselected2">2</label>
<input type="radio" id="sizeselected3" name="downloadsize" value="GB"
<label for="sizeselected3">3</label>
</form>
Similarly for other form...change the ids.

You need to use unique id on your input
<form class="sizeselect" name="sizeselect">
<input type="radio" id="sizeselected1" name="downloadsize" value="KB"><label for="sizeselected1">1</label>
<input type="radio" id="sizeselected2" name="downloadsize" value="MB"><label for="sizeselected2">2</label>
<input type="radio" id="sizeselected3" name="downloadsize" value="GB"><label for="sizeselected3">3</label>
</form>
<form class="speedselect" name="speedselect">
<input type="radio" id="speedselected11" name="downloadspeed" value="Kbps"><label for="speedselected11">11</label>
<input type="radio" id="speedselected12" name="downloadspeed" value="Mbps"> <label for="speedselected12">12</label>
<input type="radio" id="speedselected13" name="downloadspeed" value="Gbps"> <label for="speedselected13">13</label>
</form>

Since you're using custom checkboxes, the checked state is triggered when you click the label - but all of the labels are for the same input (sizeselected). Just change the IDs for each input and it'll work as you expect it to!
<form class="sizeselect" id="sizeselect" name="sizeselect">
<input type="radio" id="sizeselected" name="downloadsize" value="KB">
<label for="sizeselected">1</label>
<input type="radio" id="sizeselected2" name="downloadsize" value="MB">
<label for="sizeselected2">2</label>
<input type="radio" id="sizeselected3" name="downloadsize" value="GB">
<label for="sizeselected3">3</label>
</form>
https://codepen.io/will0220/pen/KrmZqr

Related

Form button style css change to default style in responsive

The form send button changes from blue styled in my css to html deafult send form button. I want my blue style in any window size. Here is my code:
.form-inline button {
padding: 10px 20px;
background-color: dodgerblue;
border: 1px solid #ddd;
color: white;
cursor: pointer;
}
.form-inline button:hover {
background-color: royalblue;
}
<form class="form-inline" action="/action_page.php">
<input type="name" id="name" placeholder="Namn" name="name">
<input type="email" id="email" placeholder="Email" name="email">
<input type="tel" id="tel" placeholder="Tel" name="tel">
<input type="srv" id="ser" placeholder="Välj tjänst" name="ser">
<input type="date" id="date" placeholder="Datum" name="date">
<label>
<input type="checkbox" name="remember">Remember me
</label>
<button type="submit">SEND</button>
</form>

CSS Star Ratings with Radio Buttons

I am trying to change a radio button form to a Star Rating System. (https://jsfiddle.net/dtau58g6/) . Unfortunately, the html is generated by WordPress so I can only edit the CSS. My problem is that the hover and checked do not work as expected.
What I want is when the second star is selected then, the first one is full as well.
Also, when we hover over the third star, the first and second stars are full as well.
If the third item is selected, and we hover over the second star, then only the first and the second stars are full. But when we remove our mouse the the third star becomes full again as it was already selected.
.form-group {
display: flex;
}
.form-check-inline .rating {
display: none;
}
.form-check-inline span {
padding-right: 2%;
cursor: pointer;
color: transparent;
}
.form-check-inline span:before {
content: '\2606';
color: gold;
}
.form-check-inline span:hover:before,
.form-check-inline span:hover ~ span:before {
content: '\2605';
color: gold;
}
.form-check-inline .rating:checked ~ span:before {
content: '\2605';
color: gold;
}
<div class="form-group">
<div class="form-check-inline">
<label class="form-check-label" for="1">
<input type="radio" id="1" value="1" name="rating" class="rating" />
<span class="wpcomment-input-option-label wpcomment-label-radio">1</span>
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label" for="2">
<input type="radio" id="2" value="2" name="rating" class="rating" checked="checked"/>
<span class="wpcomment-input-option-label wpcomment-label-radio">2</span>
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label" for="3">
<input type="radio" id="3" value="3" name="rating" class="rating" />
<span class="wpcomment-input-option-label wpcomment-label-radio">3</span>
</label>
</div>
</div>
The answer is 'yes you can' but with a caveat that this uses the :has() pseudo class which isn't implemented in all browsers (e.g. firefox) yet.
It's possible to tidy these rules up a bit using :where() too.
See below
.form-group {
display: flex;
}
.form-check-inline .rating {
display: none;
}
.form-check-inline span {
padding-right: 2%;
cursor: pointer;
color: transparent;
}
.form-check-inline span:before {
content: '\2606';
color: gold;
}
.form-check-inline span:hover:before,
.form-check-inline span:hover~span:before {
content: '\2605';
color: gold;
}
.form-check-inline .rating:checked~span:before {
content: '\2605';
color: gold;
}
.form-group:has(input[id="2"]:checked) input[id='1']+span:before {
content: '\2605';
color: gold;
}
.form-group:has(input[id="3"]:checked) input[id='1']+span:before,
.form-group:has(input[id="3"]:checked) input[id='2']+span:before {
content: '\2605';
color: gold;
}
.form-group:has(input[id="2"]:hover) input[id='1']+span:before {
content: '\2605';
color: gold;
}
.form-group:has(input[id="3"]:hover) input[id='1']+span:before,
.form-group:has(input[id="3"]:hover) input[id='2']+span:before {
content: '\2605';
color: gold;
}
<div class="form-group">
<div class="form-check-inline">
<label class="form-check-label" for="1">
<input type="radio" id="1" value="1" name="rating" class="rating" />
<span class="wpcomment-input-option-label wpcomment-label-radio">1</span>
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label" for="2">
<input type="radio" id="2" value="2" name="rating" class="rating" checked="checked" />
<span class="wpcomment-input-option-label wpcomment-label-radio">2</span>
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label" for="3">
<input type="radio" id="3" value="3" name="rating" class="rating" />
<span class="wpcomment-input-option-label wpcomment-label-radio">3</span>
</label>
</div>
</div>

Wordpress Divi Custom CSS on HTML Form

I have a wordpress site and I am customising it with the Divi theme. I have added an HTML form to a 'Code' module and it works great. However I cannot work out where I should put the CSS. I have tried to 'Custom CSS' areas of both the row and module itself. Perhaps there is something wrong in the code? I have pasted it below. Thanks!
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=number], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #ffffff;
padding: 20px;
}
<font face="helvetica"
<META HTTPS-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <FORM> element to your page. -->
<!-- ---------------------------------------------------------------------- -->
<form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" target='_parent'>
<input type=hidden name="oid" value="00D0Y0000034cvq">
<input type=hidden name="retURL" value="https://globalstudyuk.com/success-qatar">
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: These fields are optional debugging elements. Please uncomment -->
<!-- these lines if you wish to test in debug mode. -->
<!-- <input type="hidden" name="debug" value=1> -->
<!-- <input type="hidden" name="debugEmail" -->
<!-- value="kasper.martlev#weare4c.com"> -->
<!-- ---------------------------------------------------------------------- -->
<label for="first_name">First Name</label> <input id="first_name" maxlength="40" name="first_name" size="20" type="text" required=true/><br><br>
<label for="last_name">Last Name</label> <input id="last_name" maxlength="80" name="last_name" size="20" type="text" required=true /><br><br>
Date of Birth: <span class="dateInput dateOnlyInput"> <input id="00N0Y00000RWiNa" name="00N0Y00000RWiNa" size="12" type="text" name="inputBox" placeholder=" DD/MM/YYYY" /></span><br><br>
<label for="mobile">Mobile</label> <input id="mobile" maxlength="40" name="mobile" size="20" type="number" pattern="\d*" required=true/><br><br>
<label for="email">Email</label> <input id="email" pattern="[^ #]*#[^ #]*" maxlength="80" name="email" size="20" type="text" required=true /><br><br>
Current/Previous School/University: <input id="00N0Y00000RWiNZ" maxlength="100" name="00N0Y00000RWiNZ" size="20" type="text" required=true /><br><br>
Course you would like to study: <input id="00N0Y00000RWiNi" maxlength="255" name="00N0Y00000RWiNi" size="20" type="text" required=true /><br><br>
<label for="lead_source">Where did you hear about us?</label> <select id="lead_source" name="lead_source"><option value="">--None--</option>
<option value="Instagram">Instagram</option>
<option value="Facebook">Facebook</option>
<option value="Twitter">Twitter</option>
<option value="Google">Google</option>
<option value="British Council">British Council</option>
<option value="Career day">Career day</option>
<option value="Deferred">Deferred</option>
<option value="Flier / Poster">Flier or Poster</option>
<option value="GSUK Alumni">GSUK Alumni</option>
<option value="GSUK_Website">GSUK_Website</option>
<option value="Other_(Please specify)">Other</option>
<option value="Referral_(Please specify)">Referral</option>
<option value="School Counsellor_(Please specify)">School Counsellor</option>
<option value="School Presentation">School Presentation</option>
<option value="School Tour">School Tour</option>
<option value="University Website_(Please specify)">University Website</option>
<option value="Web">Web</option>
</select><br><br>
<input type=hidden id="00N0Y00000RWvPA" name="00N0Y00000RWvPA" type="checkbox" value="1" />
<input type=hidden id="country_code" name="country_code"value="QA" />
<input type=hidden id="city" name="city" value="Doha" />
<center><input type="submit" name="submit"></center>
</form>
login to your dashboard -> click on Appearance -> click Customize -> click on Additional CSS and paste your css in that.
We resolved the issue by removing
div {
border-radius: 5px;
background-color: #ffffff;
padding: 20px;
}
Although this would work fine on most pages, it was causing white boxes to appear in strange places, presumably due to the CMS we were using building pages in columns.

how to change the background color of the input when checked? [duplicate]

This question already has answers here:
Why cannot change checkbox color whatever I do? [duplicate]
(16 answers)
Closed 4 years ago.
input:checked {
height: 20px;
width: 20px;
background-color: red;
}
input:not(:checked) + label {
opacity: 0.7;
}
<html>
<body>
<form action="">
<input type="radio" checked="checked" value="male" name="gender"> <label>Male</label><br>
<input type="radio" value="female" name="gender"> <label>Female</label><br>
<input type="checkbox" checked="checked" value="Bike"> <label>I have a bike</label><br>
<input type="checkbox" value="Car"> <label>I have a car </label>
</form>
Here i have set of radio and checkbox inputs and i am trying to change the background color of the checked input. I'm able to alter the height and width of the element but not the background-color of the inputs.
Where am doing wrong?
Here is how to do it:
input:checked {
height: 15px;
width: 15px;
border-radius:50%;
background-color: red;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
input:checked + label {
background-color: red;
}
input:not(:checked) + label {
opacity: 0.7;
}
<html>
<body>
<form action="">
<input type="radio" checked="checked" value="male" name="gender"> <label>Male</label><br>
<input type="radio" value="female" name="gender"> <label>Female</label><br>
<input type="checkbox" checked="checked" value="Bike"> <label>I have a bike</label><br>
<input type="checkbox" value="Car"> <label>I have a car </label>
</form>

Problems with some radio buttons in html forms

I am trying to align this radio buttons on my form, but for some reason they are kinda big and the texts are way above.
Here is my html page:
<div id="sabores">
<form action="" method="post">
<input type="radio" name="txt_sabor" value="natural" class="radiobtn" /> Natural </br>
<input type="radio" name="txt_sabor" value="laranja_com_acerola" class="radiobtn" /> Laranja com Acerola </br>
<input type="radio" name="txt_sabor" value="morango" class="radiobtn" /> Morango </br>
<input type="radio" name="txt_sabor" value="limao" class="radiobtn" /> Limão </br>
<input type="radio" name="txt_sabor" value="acai_com_guarana" class="radiobtn" /> Açaí com Guaraná</br>
<input type="radio" name="txt_sabor" value="uva" class="radiobtn" /> Uva </br>
<input type="radio" name="txt_sabor" value="abacaxi" class="radiobtn" /> Abacaxi </br>
</form>
</div>
and here is my CSS:
#sabores{
width: 370px;
height: 215px;
border: 1px solid #ccc;
float: left;
margin-top: 10px;
background: #fff;
color: #667;
font-size: 12px;
}
#sabores h2{
width: 364px;
color: #333;s
}
#sabores .radiobtn{
width: 15px;
height: 20px;
margin-left: 10px;
padding: 0 5px 0 5px;
display: block;
clear: left;
float: left;
vertical-align:bottom;
margin-top: 10px;
}
Your have mistype your br, instead of <br />. And to correct your problem and add a good accessibility practice at same time you can wrap your radio button with text in a label. You can use paragraphs <p> instead of <br /> too. And remove your clear: left; float:left you don't need to precise display:block if your element is floating.
#sabores .radiobtn{
width: 15px;
height: 20px;
margin-left: 10px;
padding: 0 5px 0 5px;
vertical-align:bottom;
margin-top: 10px;
}
<div id="sabores">
<form action="" method="post">
<label for="txt_sabor_natural"><!-- for with id value of input inside it-->
<input type="radio" name="txt_sabor" id="txt_sabor_natural" value="natural" class="radiobtn" /> Natural </label><br />
<label for="laranja">
<input type="radio" name="txt_sabor" id="laranja" value="laranja_com_acerola" class="radiobtn" /> Laranja com Acerola</label><br />
<label for="morango">
<input type="radio" name="txt_sabor" id="morango" value="morango" class="radiobtn" /> Morango </label><br />
<label for="limao">
<input type="radio" name="txt_sabor" id="limao" value="limao" class="radiobtn" /> Limão </label><br />
<label for="acai_com_guarana">
<input type="radio" name="txt_sabor" id="acai_com_guarana" value="acai_com_guarana" class="radiobtn" /> Açaí com Guaraná </label><br />
<label for="uva">
<input type="radio" name="txt_sabor" id="uva" value="uva" class="radiobtn" /> Uva </label><br />
<label for="abacaxi">
<input type="radio" name="txt_sabor" id="abacaxi" value="abacaxi" class="radiobtn" /> Abacaxi </label><br />
</form>
</div>
Better solution is to use an unordered list ul with li for each couple label + input or paragraphs, and remove your fixed height from sabores div :
<div id="sabores">
<form action="" method="post">
<p>
<label for="txt_sabor_natural"><!-- for with id value of input inside it-->
<input type="radio" name="txt_sabor" id="txt_sabor_natural" value="natural" class="radiobtn" /> Natural </label></p>
<p>
<label for="laranja">
<input type="radio" name="txt_sabor" id="laranja" value="laranja_com_acerola" class="radiobtn" /> Laranja com Acerola</label></p>
<p>
<label for="morango">
<input type="radio" name="txt_sabor" id="morango" value="morango" class="radiobtn" /> Morango </label></p>
<p>
<label for="limao">
<input type="radio" name="txt_sabor" id="limao" value="limao" class="radiobtn" /> Limão </label></p>
<p>
<label for="acai_com_guarana">
<input type="radio" name="txt_sabor" id="acai_com_guarana" value="acai_com_guarana" class="radiobtn" /> Açaí com Guaraná </label></p>
<p>
<label for="uva">
<input type="radio" name="txt_sabor" id="uva" value="uva" class="radiobtn" /> Uva </label></p>
<p>
<label for="abacaxi">
<input type="radio" name="txt_sabor" id="abacaxi" value="abacaxi" class="radiobtn" /> Abacaxi </label></p>
</form>
</div>
With style :
/*previous style*/
#sabores{
width: 370px;
/*height: 215px; don't need*/
border: 1px solid #ccc;
float: left;
margin-top: 10px;
background: #fff;
color: #667;
font-size: 12px;
}
#sabores .radiobtn{
width: 15px;
height: 20px;
margin-left: 10px;
padding: 0 5px 0 5px;
vertical-align:bottom;
}
#sabores p {
margin-bottom: 10px;
margin-top: 0;
}
Make the following changes to this class:
#sabores .radiobtn{
width: 15px;
height: 20px;
margin-left: 10px;
padding: 0 5px 0 5px;
margin-top: 10px;
vertical-align:bottom;
/*
Remove following css properties
display: block;
clear: left;
float: left;
*/
}
fiddle
Please pay more attention the follow class:
#sabores .radiobtn{
width: 15px;
height: 20px;
margin-left: 10px;
padding: 0 5px 0 5px;
display: block;
clear: left;
float: left;
vertical-align:bottom;
margin-top: 10px;
}
as you see, you use these attributes:
display:block; clear: left; float: left;
It makes your input Element out of page flow, so you can remove these attribute and everything will be ok!
I advise you can read it about Visual formatting model.(click here)

Resources