Problems with some radio buttons in html forms - css

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)

Related

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.

Labels inside a input

How to put form labels inside a input form only on mobile?
example:
my code:
<form>
<div class="form-group">
<label class="form-control-label" for="firstName">Firstname</label>
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="Firstname" required />
</div>
<div class="form-group">
<label class="form-control-label" for="lastName">Lastname</label>
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Lastname" required />
</div>
<div class="form-group">
<label class="form-control-label" for="phone_number">Mobile Number</label>
<input type="text" class="form-control" id="phone_number" name="phone_number" placeholder="A valid 9 or 10 digit phone number" maxlength="10"required pattern="0[689]?[0-9]{8}" />
</div>
</form>
Something like this? I changed the position of input and label in the HTML
.form-group {
position: relative;
min-height: 3.5em;
}
input.form-control {
height: 3em;
position: absolute;
top: 0;
left: 0;
}
label.form-control-label {
position: absolute;
font-size: .8em;
top: 0;
left: 5px;
text-transform: uppercase;
}
<form>
<div class="form-group">
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="Firstname" required />
<label class="form-control-label" for="firstName">Firstname</label>
</div>
<div class="form-group">
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Lastname" required />
<label class="form-control-label" for="lastName">Lastname</label>
</div>
<div class="form-group">
<input type="text" class="form-control" id="phone_number" name="phone_number" placeholder="A valid 9 or 10 digit phone number" maxlength="10" required pattern="0[689]?[0-9]{8}" />
<label class="form-control-label" for="phone_number">Mobile Number</label>
</div>
</form>
You can use like the below method. We have to write mobile screen style with in the media queries
body{
font-family:arial;
}
.form-group{
position:relative;
}
.input-element{
padding:30px 5px 5px 5px;
width:100%;
border:1px solid #CCC;
}
#media screen and (max-width: 767px) {
.label-element{
position:absolute;
top:5px;
left:5px;
font-size:12px;
color:#666;
}
}
<div class="form-group"><label class="label-element">First Name</label>
<input type="text" class="input-element"/></div>
I've just added a border to form-group and overwritten some bootstrap code.
For mobile only, try to use CSS3 Media Queries.
You could try this:
.form-group {
border: 1px solid black; /* Change border width and color here */
}
/* the !important declaration is for this snippet, because this snippet include bootstrap after this declarations **/
.form-control {
border: none !important; /* No border for input */
box-shadow: none !important; /* No border for input */
}
.form-control:focus {
box-shadow: none !important; /* Remove the blue shining at focus */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<form>
<div class="form-group">
<label class="form-control-label" for="firstName">Firstname</label>
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="Firstname" required />
</div>
<div class="form-group">
<label class="form-control-label" for="lastName">Lastname</label>
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Lastname" required />
</div>
<div class="form-group">
<label class="form-control-label" for="phone_number">Mobile Number</label>
<input type="text" class="form-control" id="phone_number" name="phone_number" placeholder="A valid 9 or 10 digit phone number" maxlength="10" required pattern="0[689]?[0-9]{8}" />
</div>
</form>
Inspired by another answer, here is a short way to do it:
.input-group {
position: relative;
}
.input-label {
position: absolute;
top: 5px;
left: 5px;
color: #666;
}
.input-element {
padding: 30px 5px 5px 5px;
}
<div class="input-group">
<label class="input-label">First name</label>
<input type="text" class="input-element" />
</div>

Checkbox image styling not working correctly within form on IE

I've got a form in which I've got checkboxes styled with images. All working nicely in Chrome, FF, Edge... but not IE.
Basically, the CSS styling works how I want it to in IE, when the checkboxes are NOT within a form, but as soon as the form tags go around them, they stop working properly. Instead, rather than clicking the image to get the checked effect, I have to click beside the image.
Anyone help me out with what I have to do to make it work correctly in IE?
I've tried it in IE 11. Why would making it within a form cause it to change behaviour?
I'm not a natural coder, and most of the CSS below was adapted from another question I found on here.
Jsfiddle - https://jsfiddle.net/vpLf8vpw/5/
HTML
<form>
<input id="cb1" name="product1[]" type="checkbox" value=" Classic switch" />
<label for="cb1">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb2" name="product2[]" type="checkbox" value=" Right angle switch" />
<label for="cb2">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb3" name="product3[]" type="checkbox" value=" Adaptor" />
<label for="cb3">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb4" name="product4[]" type="checkbox" value=" Blow switch" />
<label for="cb4">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb5" name="product5[]" type="checkbox" value=" Cable" />
<label for="cb5">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
CSS
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
border: none;
padding: none;
display: block;
position: relative;
margin: none;
cursor: pointer;
}
label img {
height: 125px;
width: 125px;
transition-duration: 0.2s;
transform-origin: 50% 50%;
}
:checked + label img {
transform: scale(1);
box-shadow: 0 0 20px #ff0;
z-index: -1;
}
This looks like a duplicate of another question: Image label for input in a form not clickable in IE
updated fiddle: https://jsfiddle.net/dnptmydo/
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
border: none;
padding: none;
display: inline-block;
position: relative;
margin: none;
/* cursor: pointer; */
}
label img {
height: 125px;
width: 125px;
transition-duration: 0.2s;
transform-origin: 50% 50%;
pointer-events: none;
}
:checked + label img {
transform: scale(1);
box-shadow: 0 0 20px #ff0;
z-index: -1;
}
<form>
<input id="cb1" name="product1[]" type="checkbox" value=" Classic switch" />
<label for="cb1">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb2" name="product2[]" type="checkbox" value=" Right angle switch" />
<label for="cb2">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb3" name="product3[]" type="checkbox" value=" Adaptor" />
<label for="cb3">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb4" name="product4[]" type="checkbox" value=" Blow switch" />
<label for="cb4">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
<input id="cb5" name="product5[]" type="checkbox" value=" Cable" />
<label for="cb5">
<img src="http://www.4jewelersonly.com/wp-content/uploads/sites/16/2015/03/127880648-670x670.jpg" alt="" />
</label>
</form>

Font Awesome Icon before input

I am trying to display fa-icon before my input.
My html code is as follows:
<table width="788" border="0">
<tr> <td> <input type="hidden" name="c_id" id="c_id" value="<?php echo $id; ?>"> </td> </tr>
<tr>
<td width="150"><p>
<label for="firstname">Customer First Name</label>
</p>
<p>
<label class="input">
<i class="fa fa-user" aria-hidden="true"></i>
<input class="myinput" type="text" name="firstname" id="fn" placeholder="First Name" value="<?php echo $firstname1; ?>" >
</label>
</p></td>
<td width="243"><p>
<label for="middlename">Customer Middle Name</label>
</p>
<p>
<label class="input">
<i class="fa fa-user" aria-hidden="true"></i>
<input class="myinput" type="text" name="middlename" id="middlename" value="<?php echo $m_name2; ?>" placeholder="Middle Name"> </label>
</p></td>
<td width="250"><p>
<label for="lastname">Customer Last Name</label>
</p>
<p>
<label class="input">
<i class="fa fa-user" aria-hidden="true"></i>
<input class="myinput" type="text" name="lastname" id="lastname" placeholder="Last Name" value="<?php echo $lastname3; ?> " >
</label>
</p></td></tr>
</table>
CSS is as follows:
i {
color: #c0c2c7;
margin-right: 10px;
margin-top: 4px;
padding: 2px 8px;
float:left;
}
.myinput
{
width:100%;
float:left;
}
input
{
background-color: #3CBC8D;
color: white;
display: inline-block;
padding: 5px 10px;
float:left;
width:90%;
}
The fa icon appears above the input field. I want the icon to appear before the input field. Is there any solution for that? I tried display inline and inline block properties. What can be the solution to this?
Solved : Easy and best to implement by using below concept:
.input{position:relative}
.icon-wrapper{position:absolute; display:block; width:25px; height:25px; left:1px; top:1px;}
.myinput{padding-left:15px;}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<label class="input">
<span class="icon-wrapper"><i class="fa fa-user" aria-hidden="true"></i></span>
<input class="myinput" type="text" name="firstname" id="fn" placeholder="First Name" value="" >
</label>
Try this:
i.fa{
color: #c0c2c7;
margin-right: 10px;
margin-top: 4px;
padding: 2px 8px;
//float:left;
display: inline-block;
width:10%;
}
.myinput
{
//width:100%;
//float:left;
}
input
{
background-color: #3CBC8D;
color: white;
display: inline-block;
padding: 5px 10px;
//float:left;
width:90%;
}
try this
i {
color: #c0c2c7;
margin-right: 10px;
margin-top: 4px;
padding: 2px 8px;
float:left;
display: inline-block;
width: 10%;
}
and remove
.myinput
{
width:100%;
float:left;
}
use bootstrap classes to achieve this functionality like below
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
</div>
More Examples

Relative positioning in CSS is completely different in Safari and Firefox?

I am new to CSS and have been trying to create a web form with the radio buttons aligned next to text fields. However, in Firefox the radio boxes look fine, but when I check in Safari the radio boxes are in the middle of the text fields.
The CSS looks like this:
input#answers
{
display: block;
height: 31px;
left: 87px;
position: relative;
top: 0px;
width: 350px;
}
input[type="radio"]
{
display: inline- block;
height: 20px;
left: 249px;
position: relative;
top: -30px;
vertical-align: middle;
}
and the HTML like this:
<form id="quizCreator" name="quizCreator" method="post" action="quiz.maker.php">
<label><span><img src="images/quizcreatorText.ques.png" hspace="79px" vspace="70px" class="titles" /></span> <br />
<input type="text" name="question" id="question" />
</label>
<label><img src="images/quizcreatorText.ans.png" hspace="79px" vspace="70px" class="titles" id="ans" /> <br />
<input type="hidden" name="creator" value="myform" />
<br />
<input type="text" name="answer1" id="answers" />
</label>
<label>
<input type="radio" name="radio" id="radio1" value="radio1" />
</label>
<label>
<input type="text" name="answer2" id="answers" />
</label>
<label>
<input type="radio" name="radio" id="radio3" value="radio2" />
</label>
<label>
<input type="text" name="answer3" id="answers" />
</label>
<label>
<input name="radio" type="radio" class="radio" id="radio3" value="radio3" />
</label>
<label>
<input type="text" name="answer4" id="answers" />
</label>
<label>
<input name="radio" type="radio" id="radio4" value="radio4" />
</label>
<span><input type="image" src="images/quiznameText.next.png" name="nextPage" id="nextPage" class="nxtbutton" /></span>
</form>
I've tried using relative positioning and margins, but while it fixes the problems in Safari, Firefox then looks wrong. Is there a way to make them both work as I want with a single set of code? (And what about MSIE?)
You should not be using relative positioning for this.
The proper structure is something like this (not sure if you want the text before or after):
<div class="answers">
<ul>
<li><label>your text</label><input type="radio" /></li>
...repeat...
</ul>
</div>
CSS:
.answers ul, .answers li {
list-style-type:none;
margin:0;
padding:0;
}
.answers li {
clear:both
}
.answers label {
display:block;
float:left;
width:100px;
}
.answers input {
display:block;
float:left;
}

Resources