How can I neatly line up the checkbox and radio box - css

I'm not sure how I'm suposed neatly line inputs in a row. I tried using flex and position: relative (for the label) but that didn't work for me. I'm trying to make it look like this for example for both my checkboxes and radios:
But this is what I got instead:
Please explain how I can find a solution to this problem.
https://codepen.io/Yisego45873/pen/WNEJPVx
#import url('https://fonts.googleapis.com/css2?family=Playfair+Display&family=Quicksand&display=swap');
* {
box-sizing: border-box;
text-align: center;
font-family: 'Playfair Display', serif;
font-family: 'Quicksand', sans-serif;
}
body {
background: linear-gradient(40deg, transparent 40%, rgb(41, 39, 39)), linear-gradient(-40deg, rgb(78, 75, 75) 20%, #81777d 90%);
}
header {
color: white;
}
div {
background-color: rgb(68, 65, 65);
padding: 35px;
opacity: 200%;
margin: 0 30px;
border: rgb(41, 39, 39) solid 3px;
border-radius: 3px;
margin-bottom: 20px;
}
form {
color: white;
}
#sect-1 label {
margin: 0 0 15px;
color: white;
}
#sect-1 input {
border: white;
width: 50%;
border-radius: 2px;
padding: 10px;
margin: 15px;
}
select {
border: white;
width: 50%;
color: #4d4a4a;
border-radius: 1px;
padding: 10px;
margin: 15px;
color: black;
}
span {
font-style: italic;
opacity: 80%;
}
select option {
color: black;
}
#range {
width: 50%;
}
input[type=checkbox] {
-ms-transform: scale(1.5);
/* IE */
-moz-transform: scale(1.5);
/* FF */
-webkit-transform: scale(1.5);
/* Safari and Chrome */
-o-transform: scale(1.5);
/* Opera */
transform: scale(1.5);
}
input[type=radio] {
/* IE */
-ms-transform: scale(1.4);
/* FF */
-moz-transform: scale(1.4);
/* Safari and Chrome */
-webkit-transform: scale(1.4);
/* Opera */
-o-transform: scale(1.4);
transform: scale(1.4);
position: absolute;
left: 300px;
}
textarea {
padding: 5px;
margin: auto;
/* IE */
-ms-transform: scale(1.4);
/* FF */
-moz-transform: scale(1.4);
/* Safari and Chrome */
-webkit-transform: scale(1.4);
/* Opera */
-o-transform: scale(1.4);
transform: scale(1.4);
color: black;
margin-bottom: 50px;
margin-top: 50px;
text-align: left;
}
label {
margin-top: 30px;
margin-bottom: 5px;
}
#sect-1 {
color: black;
}
input[type=submit] {
background-color: rgb(41, 39, 39);
border: rgb(41, 39, 39) 10px solid;
width: 50%;
margin-top: 10px;
border-radius: 5px;
}
input[type=submit]:hover {
background-color: rgb(110, 108, 108);
border: 10px solid rgb(110, 108, 108);
cursor: pointer;
}
#range-section {
margin-bottom: 15px;
}
#sect-2,
#sect-3 {
display: flex;
}
#sect-2,
#sect-3 label {
position: relative;
}
<header>
<h1 id="title">Art Course Survey Page</h1>
<p id="description">Any feedback would be appreciated.</p>
</header>
<div>
<form id="survey-form" action="#" method="post">
<section id="sect-1">
<label id="name-label" for="name">Name</label><br />
<input type="text" name="name" id="name" placeholder="Enter your name" required="required" /><br />
<label id="email-label" for="email">Email</label><br />
<input type="email" name="email" id="email" placeholder="Enter your email address" required="required" /><br />
<label id="number-label" for="number">Age <span>(optional)</span></label><br />
<input type="number" name="number" id="number" placeholder="Age" min="1" max="99" /><br />
<label id="gender" for="gender-drop">Gender <span>(optional)</span></label><br />
<select name="gender" id="gender-drop">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</section>
<section id="dropdown-section">
<label for="dropdown">Which course did you take?</label><br />
<select required="required" name="course" id="dropdown" size="1">
<option value="level1">Beginner Course</option>
<option value="level2">Beginner-Intermediate Course</option>
<option value="level3">Intermediate Course</option>
<option value="level4">Advanced Course</option>
<option value="level5">Expert Course</option>
</select>
</section>
<br />
<section id="range-section">
<label for="range">How was your experience?</label><br />
<small>Terrible!</small>
<input type="range" required="required" id="range" name="range" min="0" max="4" value="0" /><small>Excellent!</small>
</section>
<section id="sect-2">
<label for="y/n"> Would you recommend this course to a friend?</label><br />
<label for="yes">
<input type="radio" required="required" id="yes" name="y/n" value="Yes" checked="checked" />
Yes
</label><br />
<label for="no">
<input type="radio" required="required" id="no" name="y/n" value="No" /> No
</label><br />
<label for="maybe">
<input type="radio" required="required" id="maybe" name="y/n" value="Maybe" /> Maybe
</label><br />
</section>
<section id="sect-3">
<p>What would you like to see improved? <span>(Check all that apply)</span></p>
<label for="improve1">
<input type="checkbox" id="improve1" name="improve1" value="Layout" /> Course
Layout/Paths
</label><br />
<label for="improve2">
<input type="checkbox" id="improve2" name="improve2" value="Videos" /> Course
Videos/Instruction
</label><br />
<label for="improve3">
<input type="checkbox" id="improve3" name="improve3" value="Community" />
Community Features
</label><br />
<label for="improve4">
<input type="checkbox" id="improve4" name="improve4" value="Support-Help" /> Support
</label><br />
<label for="improve5">
<input type="checkbox" id="improve5" name="improve5" value="Other" /> Other
</label>
</section>
<section id="sect-4">
<!-- <label id="txt-label" for="textarea">Any extra comments are welcome!</label> -->
<textarea rows="4" cols="50" id="textarea" placeholder="Any extra comments, suggestions, and complaints go here."></textarea><br />
<input id="submit" type="submit" value="Submit" style="color: white;" />
</section>
</form>
</div>

I took the previous media queries out and just gave the sections those styles.
section#sect-2,
section#sect-3 {
text-align: left;
display: inline-block;
}
I also added <br> which is a line break element under your #dropdown-section next to your closing section tag.
#import url('https://fonts.googleapis.com/css2?family=Playfair+Display&family=Quicksand&display=swap');
* {
box-sizing: border-box;
text-align: center;
font-family: 'Playfair Display', serif;
font-family: 'Quicksand', sans-serif;
}
body {
background: linear-gradient(40deg, transparent 40%, rgb(41, 39, 39)),
linear-gradient(-40deg, rgb(78, 75, 75) 20%, #81777d 90%);
}
header {
color: white;
}
div {
background-color: rgb(68, 65, 65);
padding: 35px;
opacity: 200%;
margin: 0 30px;
border: rgb(41, 39, 39) solid 3px;
border-radius: 3px;
margin-bottom: 20px;
}
form {
color: white;
}
#sect-1 label {
margin: 0 0 15px;
color: white;
}
#sect-1 input {
border: white;
width: 50%;
border-radius: 2px;
padding: 10px;
margin: 15px;
}
select {
border: white;
width: 50%;
color: #4d4a4a;
border-radius: 1px;
padding: 10px;
margin: 15px;
color: black;
}
span {
font-style: italic;
opacity: 80%;
}
select option {
color: black;
}
#range {
width: 50%;
}
input[type=checkbox] {
-ms-transform: scale(1.5);
/* IE */
-moz-transform: scale(1.5);
/* FF */
-webkit-transform: scale(1.5);
/* Safari and Chrome */
-o-transform: scale(1.5);
/* Opera */
transform: scale(1.5);
}
input[type=radio] {
/* IE */
-ms-transform: scale(1.4);
/* FF */
-moz-transform: scale(1.4);
/* Safari and Chrome */
-webkit-transform: scale(1.4);
/* Opera */
-o-transform: scale(1.4);
transform: scale(1.4);
position: absolute;
left: 300px;
}
textarea {
padding: 5px;
margin: auto;
/* IE */
-ms-transform: scale(1.4);
/* FF */
-moz-transform: scale(1.4);
/* Safari and Chrome */
-webkit-transform: scale(1.4);
/* Opera */
-o-transform: scale(1.4);
transform: scale(1.4);
color: black;
margin-bottom: 50px;
margin-top: 50px;
text-align: left;
}
label {
margin-top: 30px;
margin-bottom: 5px;
}
#sect-1{
color: black;
}
input[type=submit] {
background-color: rgb(41, 39, 39);
border: rgb(41, 39, 39) 10px solid;
width: 50%;
margin-top: 10px;
border-radius: 5px;
}
input[type=submit]:hover {
background-color: rgb(110, 108, 108);
border: 10px solid rgb(110, 108, 108);
cursor: pointer;
}
#range-section{
margin-bottom: 15px;
}
#sect-2, #sect-3{
display: flex;
}
#sect-2, #sect-3 label{
position: relative;
}
section#sect-2,
section#sect-3 {
text-align: left;
display: inline-block;
}
<header>
<h1 id="title">Art Course Survey Page</h1>
<p id="description">Any feedback would be appreciated.</p>
</header>
<div>
<form id="survey-form" action="#" method="post">
<section id="sect-1">
<label id="name-label" for="name">Name</label><br />
<input type="text" name="name" id="name" placeholder="Enter your name" required="required" /><br />
<label id="email-label" for="email">Email</label><br />
<input type="email" name="email" id="email" placeholder="Enter your email address" required="required" /><br />
<label id="number-label" for="number">Age <span>(optional)</span></label><br />
<input type="number" name="number" id="number" placeholder="Age" min="1" max="99" /><br />
<label id="gender" for="gender-drop">Gender <span>(optional)</span></label><br />
<select name="gender" id="gender-drop">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</section>
<section id="dropdown-section">
<label for="dropdown">Which course did you take?</label><br />
<select required="required" name="course" id="dropdown" size="1">
<option value="level1">Beginner Course</option>
<option value="level2">Beginner-Intermediate Course</option>
<option value="level3">Intermediate Course</option>
<option value="level4">Advanced Course</option>
<option value="level5">Expert Course</option>
</select>
</section>
<br>
<section id="range-section">
<label for="range">How was your experience?</label><br />
<small>Terrible!</small>
<input type="range" required="required" id="range" name="range" min="0" max="4" value="0" /><small>Excellent!</small>
</section>
<section id="sect-2">
<label for="y/n"> Would you recommend this course to a friend?</label><br />
<label for="yes">
<input type="radio" required="required" id="yes" name="y/n" value="Yes" checked="checked" />
Yes
</label><br />
<label for="no">
<input type="radio" required="required" id="no" name="y/n" value="No" /> No
</label><br />
<label for="maybe">
<input type="radio" required="required" id="maybe" name="y/n" value="Maybe" /> Maybe
</label><br />
</section><br>
<section id="sect-3">
<p>What would you like to see improved? <span>(Check all that apply)</span></p>
<label for="improve1">
<input type="checkbox" id="improve1" name="improve1" value="Layout" /> Course
Layout/Paths
</label><br />
<label for="improve2">
<input type="checkbox" id="improve2" name="improve2" value="Videos" /> Course
Videos/Instruction
</label><br />
<label for="improve3">
<input type="checkbox" id="improve3" name="improve3" value="Community" />
Community Features
</label><br />
<label for="improve4">
<input type="checkbox" id="improve4" name="improve4" value="Support-Help" /> Support
</label><br />
<label for="improve5">
<input type="checkbox" id="improve5" name="improve5" value="Other" /> Other
</label>
</section>
<section id="sect-4">
<!-- <label id="txt-label" for="textarea">Any extra comments are welcome!</label> -->
<textarea rows="4" cols="50" id="textarea" placeholder="Any extra comments, suggestions, and complaints go here."></textarea><br />
<input id="submit" type="submit" value="Submit" style="color: white;" />
</section>
</form>
</div>

Related

HTML form field won't keep pseudoclass

I have the following form:
body {
background: #fff;
color: 404040
}
form {
display: block;
position: relative;
width: 80%;
background: #f9f9f9;
margin: 10px auto;
padding: 30px;
}
label {
display: block;
position: relative;
top: -20px;
left: 0px;
color: #999;
font-family: 'Helvetica', sans-serif;
font-size: 16px;
z-index: 1;
transition: all 0.3s ease-out;
}
input,
input:optional {
display: block;
position: relative;
background: none;
border: none;
border-bottom: 1px solid #ddd;
width: 100%;
font-family: 'Helvetica', sans-serif;
font-weight: bold;
font-size: 16px;
z-index: 2;
}
input:focus,
input:valid {
outline: none;
border-bottom: 1px solid #00aced;
}
input:focus+label,
input:required:valid+label {
top: -40px;
font-size: 11px;
color: #00aced;
}
.divider {
position: relative;
height: 30px;
width: auto;
background: none;
}
#hex1 {
width: 75px;
margin: 10px auto;
}
.headline {
margin-left: 100px;
font-size: 24px;
}
.submitBtn {
width: 250px;
height: 75px;
border-radius: 3px;
background: #37afac;
margin: 0 auto;
color: #fff
}
#title {
margin-top: -60px;
margin-left: 80px;
margin-bottom: 20px;
}
<form>
<h3>Details about the person you are reporting:</h3>
<div class='divider'></div>
<input type="text" name="firstname" required autocomplete="off" />
<label for="firstname">First Name</label>
<div class='divider'></div>
<input type="text" name="lastname" required autocomplete="off" />
<label for="lastname">Last Name</label>
<div class='divider'></div>
<input type="text" name="age" class="test" autocomplete="off" />
<label for="age">Age</label>
<div class='divider'></div>
<input type="text" name="gender" required autocomplete="off" />
<label for="gender">Gender</label>
<div class='divider'></div>
<input type="text" name="address 1" autocomplete="off" />
<label for="address1">Address 1</label>
<div class='divider'></div>
<input type="text" name="address 2" autocomplete="off" />
<label for="address2">Address 2</label>
<div class='divider'></div>
<input type="text" name="city" required autocomplete="off" />
<label for="city">City</label>
<div class='divider'></div>
<input type="text" name="state" required autocomplete="off" />
<label for="state">State</label>
<div class='divider'></div>
<input type="text" name="position" autocomplete="off" />
<label for="Position">Position (coach, referee, etc)</label>
<div class='divider'></div>
<input type="text" name="program" required autocomplete="off" />
<label for="Program">Program where individual works</label>
<div class='divider'></div>
<input type="text" name="IncidentDescription" required autocomplete="off" />
<label for="IncidentDescription">Incident description</label>
<div class='divider'></div>
<input type="text" name="IncidentLocation" required autocomplete="off" />
<label for="IncidentLocation">Incident location</label>
<div class='divider'></div>
Codepen: https://codepen.io/anon/pen/PazrBw
As each input receives focus, it animates via receiving a class in css. Using basic html5 validation, it's supposed to retain that class to show that it's been properly filled out.
My problem is that I need some fields to be not required. When fields are not marked required, the form automatically applies some of the :valid pseudoclass (the blue underline). The even bigger issue is that when it loses focus, it loses that class and collapses the label back down onto the input text.
What am I missing here? thank you!
You are not missing anything, it all behaves the way it's supposed to be based on your code. So you need an alternative approach.
I suggest using :placeholder-shown selector instead of :valid. This way, empty optional fields will no longer get selected.
To make this work, you first need to add placeholder=" " to your inputs. This feels a bit hacky because this way you are losing the ability to use placeholders in case you need them but remember that you are already saying no to using placeholders by putting labels in their place (well, if you ever need to include placeholders for the sake of accessibility, do it, and instead of empty placeholders put real ones, then hide them with CSS. Another topic, another time).
:placeholder-shown does not have IE/old browser support so we'll go with a good example of progressive enhancement here:
Label text will be already minimised and positioned on top of the input as a default (that is top: -40px; font-size: 11px;) so that it does not mess with user input. I believe that is good enough for IE/old browsers.
Then we add the nice animation effect for browsers that do support :placeholder-shown by including following styles:
input:not(:focus):placeholder-shown + label {
top: -20px;
font-size: 16px;
}
:not(:focus) is necessary to resize and reposition label as soon as user focuses an input because some browsers show placeholder even after focus (and hide it only after user starts typing).
body {
background: #fff;
color: 404040
}
form {
display: block;
position: relative;
width: 80%;
background: #f9f9f9;
margin: 10px auto;
padding: 30px;
}
label {
display: block;
position: relative;
/* top: -20px; */
top: -40px;
left: 0px;
color: #999;
font-family: 'Helvetica', sans-serif;
/* font-size: 16px; */
font-size: 11px;
z-index: 1;
transition: all 0.3s ease-out;
}
input/*,
input:optional */ {
display: block;
position: relative;
background: none;
border: none;
border-bottom: 1px solid #ddd;
width: 100%;
font-family: 'Helvetica', sans-serif;
font-weight: bold;
font-size: 16px;
z-index: 2;
}
input:focus/*,
input:valid*/ {
outline: none;
border-bottom: 1px solid #00aced;
}
input:focus+label/*,
input:required:valid+label*/ {
color: #00aced;
}
/* New styles >> */
input:not(:focus):placeholder-shown + label {
top: -20px;
font-size: 16px;
}
/* << */
.divider {
position: relative;
height: 30px;
width: auto;
background: none;
}
#hex1 {
width: 75px;
margin: 10px auto;
}
.headline {
margin-left: 100px;
font-size: 24px;
}
.submitBtn {
width: 250px;
height: 75px;
border-radius: 3px;
background: #37afac;
margin: 0 auto;
color: #fff
}
#title {
margin-top: -60px;
margin-left: 80px;
margin-bottom: 20px;
}
<form>
<h3>Details about the person you are reporting:</h3>
<div class='divider'></div>
<input placeholder=" " type="text" name="firstname" required autocomplete="off" />
<label for="firstname">First Name</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="lastname" required autocomplete="off" />
<label for="lastname">Last Name</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="age" class="test" autocomplete="off" />
<label for="age">Age</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="gender" required autocomplete="off" />
<label for="gender">Gender</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="address 1" autocomplete="off" />
<label for="address1">Address 1</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="address 2" autocomplete="off" />
<label for="address2">Address 2</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="city" required autocomplete="off" />
<label for="city">City</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="state" required autocomplete="off" />
<label for="state">State</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="position" autocomplete="off" />
<label for="Position">Position (coach, referee, etc)</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="program" required autocomplete="off" />
<label for="Program">Program where individual works</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="IncidentDescription" required autocomplete="off" />
<label for="IncidentDescription">Incident description</label>
<div class='divider'></div>
<input placeholder=" " type="text" name="IncidentLocation" required autocomplete="off" />
<label for="IncidentLocation">Incident location</label>
<div class='divider'></div>

Customize Bootstrap checkboxes

I'm using Bootstrap in my Angular application and all other styles are working like they should, but checkbox style doesn't. It just look like plain old checkbox.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please log in</h2>
<label for="inputEmail" class="sr-only">User name</label>
<input [(ngModel)]="loginUser.Username" type="username" name="username" id="inputEmail" class="form-control" placeholder="User name" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input [(ngModel)]="loginUser.Password" type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<a *ngIf="register == false" (click)="registerState()">Register</a>
<div class="checkbox">
<label>
<input type="checkbox" [(ngModel)]="rememberMe" name="rememberme"> Remember me
</label>
</div>
<button *ngIf="register == false" (click)="login()" class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
</form>
</div>
What it looks like:
What I want it to look like with Bootstrap style:
Since Bootstrap 3 doesn't have a style for checkboxes I found a custom made that goes really well with Bootstrap style.
Checkboxes
.checkbox label:after {
content: '';
display: table;
clear: both;
}
.checkbox .cr {
position: relative;
display: inline-block;
border: 1px solid #a9a9a9;
border-radius: .25em;
width: 1.3em;
height: 1.3em;
float: left;
margin-right: .5em;
}
.checkbox .cr .cr-icon {
position: absolute;
font-size: .8em;
line-height: 0;
top: 50%;
left: 15%;
}
.checkbox label input[type="checkbox"] {
display: none;
}
.checkbox label input[type="checkbox"]+.cr>.cr-icon {
opacity: 0;
}
.checkbox label input[type="checkbox"]:checked+.cr>.cr-icon {
opacity: 1;
}
.checkbox label input[type="checkbox"]:disabled+.cr {
opacity: .5;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Default checkbox -->
<div class="checkbox">
<label>
<input type="checkbox" value="">
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
Option one
</label>
</div>
<!-- Checked checkbox -->
<div class="checkbox">
<label>
<input type="checkbox" value="" checked>
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
Option two is checked by default
</label>
</div>
<!-- Disabled checkbox -->
<div class="checkbox disabled">
<label>
<input type="checkbox" value="" disabled>
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
Option three is disabled
</label>
</div>
Radio
.checkbox label:after,
.radio label:after {
content: '';
display: table;
clear: both;
}
.checkbox .cr,
.radio .cr {
position: relative;
display: inline-block;
border: 1px solid #a9a9a9;
border-radius: .25em;
width: 1.3em;
height: 1.3em;
float: left;
margin-right: .5em;
}
.radio .cr {
border-radius: 50%;
}
.checkbox .cr .cr-icon,
.radio .cr .cr-icon {
position: absolute;
font-size: .8em;
line-height: 0;
top: 50%;
left: 13%;
}
.radio .cr .cr-icon {
margin-left: 0.04em;
}
.checkbox label input[type="checkbox"],
.radio label input[type="radio"] {
display: none;
}
.checkbox label input[type="checkbox"]+.cr>.cr-icon,
.radio label input[type="radio"]+.cr>.cr-icon {
opacity: 0;
}
.checkbox label input[type="checkbox"]:checked+.cr>.cr-icon,
.radio label input[type="radio"]:checked+.cr>.cr-icon {
opacity: 1;
}
.checkbox label input[type="checkbox"]:disabled+.cr,
.radio label input[type="radio"]:disabled+.cr {
opacity: .5;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
<!-- Default radio -->
<div class="radio">
<label>
<input type="radio" name="o3" value="">
<span class="cr"><i class="cr-icon fa fa-circle"></i></span>
Option one
</label>
</div>
<!-- Checked radio -->
<div class="radio">
<label>
<input type="radio" name="o3" value="" checked>
<span class="cr"><i class="cr-icon fa fa-circle"></i></span>
Option two is checked by default
</label>
</div>
<!-- Disabled radio -->
<div class="radio disabled">
<label>
<input type="radio" name="o3" value="" disabled>
<span class="cr"><i class="cr-icon fa fa-circle"></i></span>
Option three is disabled
</label>
</div>
Custom icons
You can choose your own icon between the ones from Bootstrap or Font Awesome by changing [icon name] with your icon.
<span class="cr"><i class="cr-icon [icon name]"></i>
For example:
glyphicon glyphicon-remove for Bootstrap, or
fa fa-bullseye for Font Awesome
.checkbox label:after,
.radio label:after {
content: '';
display: table;
clear: both;
}
.checkbox .cr,
.radio .cr {
position: relative;
display: inline-block;
border: 1px solid #a9a9a9;
border-radius: .25em;
width: 1.3em;
height: 1.3em;
float: left;
margin-right: .5em;
}
.radio .cr {
border-radius: 50%;
}
.checkbox .cr .cr-icon,
.radio .cr .cr-icon {
position: absolute;
font-size: .8em;
line-height: 0;
top: 50%;
left: 15%;
}
.radio .cr .cr-icon {
margin-left: 0.04em;
}
.checkbox label input[type="checkbox"],
.radio label input[type="radio"] {
display: none;
}
.checkbox label input[type="checkbox"]+.cr>.cr-icon,
.radio label input[type="radio"]+.cr>.cr-icon {
opacity: 0;
}
.checkbox label input[type="checkbox"]:checked+.cr>.cr-icon,
.radio label input[type="radio"]:checked+.cr>.cr-icon {
opacity: 1;
}
.checkbox label input[type="checkbox"]:disabled+.cr,
.radio label input[type="radio"]:disabled+.cr {
opacity: .5;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
<div class="checkbox">
<label>
<input type="checkbox" value="" checked>
<span class="cr"><i class="cr-icon glyphicon glyphicon-remove"></i></span>
Bootstrap - Custom icon checkbox
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="o3" value="" checked>
<span class="cr"><i class="cr-icon fa fa-bullseye"></i></span>
Font Awesome - Custom icon radio checked by default
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="o3" value="">
<span class="cr"><i class="cr-icon fa fa-bullseye"></i></span>
Font Awesome - Custom icon radio
</label>
</div>
You have to use Bootstrap version 4 with the custom-* classes to get this style:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- example code of the bootstrap website -->
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Check this custom checkbox</span>
</label>
<!-- your code with the custom classes of version 4 -->
<div class="checkbox">
<label class="custom-control custom-checkbox">
<input type="checkbox" [(ngModel)]="rememberMe" name="rememberme" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Remember me</span>
</label>
</div>
Documentation: https://getbootstrap.com/docs/4.0/components/forms/#checkboxes-and-radios-1
Custom checkbox style on Bootstrap version 3?
Bootstrap version 3 doesn't have custom checkbox styles, but you can use your own. In this case: How to style a checkbox using CSS?
These custom styles are only available since version 4.
/* The customcheck */
.customcheck {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.customcheck input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 5px;
}
/* On mouse-over, add a grey background color */
.customcheck:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
.customcheck input:checked ~ .checkmark {
background-color: #02cf32;
border-radius: 5px;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.customcheck input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.customcheck .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class="container">
<h1>Custom Checkboxes</h1></br>
<label class="customcheck">One
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<label class="customcheck">Two
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="customcheck">Three
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="customcheck">Four
<input type="checkbox">
<span class="checkmark"></span>
</label>
</div>
Here you have an example styling checkboxes and radios using Font Awesome 5 free[
/*General style*/
.custom-checkbox label, .custom-radio label {
position: relative;
cursor: pointer;
color: #666;
font-size: 30px;
}
.custom-checkbox input[type="checkbox"] ,.custom-radio input[type="radio"] {
position: absolute;
right: 9000px;
}
/*Custom checkboxes style*/
.custom-checkbox input[type="checkbox"]+.label-text:before {
content: "\f0c8";
font-family: "Font Awesome 5 Pro";
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
width: 1em;
display: inline-block;
margin-right: 5px;
}
.custom-checkbox input[type="checkbox"]:checked+.label-text:before {
content: "\f14a";
color: #2980b9;
animation: effect 250ms ease-in;
}
.custom-checkbox input[type="checkbox"]:disabled+.label-text {
color: #aaa;
}
.custom-checkbox input[type="checkbox"]:disabled+.label-text:before {
content: "\f0c8";
color: #ccc;
}
/*Custom checkboxes style*/
.custom-radio input[type="radio"]+.label-text:before {
content: "\f111";
font-family: "Font Awesome 5 Pro";
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
width: 1em;
display: inline-block;
margin-right: 5px;
}
.custom-radio input[type="radio"]:checked+.label-text:before {
content: "\f192";
color: #8e44ad;
animation: effect 250ms ease-in;
}
.custom-radio input[type="radio"]:disabled+.label-text {
color: #aaa;
}
.custom-radio input[type="radio"]:disabled+.label-text:before {
content: "\f111";
color: #ccc;
}
#keyframes effect {
0% {
transform: scale(0);
}
25% {
transform: scale(1.3);
}
75% {
transform: scale(1.4);
}
100% {
transform: scale(1);
}
}
<script src="https://kit.fontawesome.com/2a10ab39d6.js"></script>
<div class="col-md-4">
<form>
<h2>1. Customs Checkboxes</h2>
<div class="custom-checkbox">
<div class="form-check">
<label>
<input type="checkbox" name="check" checked> <span class="label-text">Option 01</span>
</label>
</div>
<div class="form-check">
<label>
<input type="checkbox" name="check"> <span class="label-text">Option 02</span>
</label>
</div>
<div class="form-check">
<label>
<input type="checkbox" name="check"> <span class="label-text">Option 03</span>
</label>
</div>
<div class="form-check">
<label>
<input type="checkbox" name="check" disabled> <span class="label-text">Option 04</span>
</label>
</div>
</div>
</form>
</div>
<div class="col-md-4">
<form>
<h2>2. Customs Radios</h2>
<div class="custom-radio">
<div class="form-check">
<label>
<input type="radio" name="radio" checked> <span class="label-text">Option 01</span>
</label>
</div>
<div class="form-check">
<label>
<input type="radio" name="radio"> <span class="label-text">Option 02</span>
</label>
</div>
<div class="form-check">
<label>
<input type="radio" name="radio"> <span class="label-text">Option 03</span>
</label>
</div>
<div class="form-check">
<label>
<input type="radio" name="radio" disabled> <span class="label-text">Option 04</span>
</label>
</div>
</div>
</form>
</div>
As others have said, the style you're after is actually just the Mac OS checkbox style, so it will look radically different on other devices.
In fact both screenshots you linked show what checkboxes look like on Mac OS in Chrome, the grey one is shown at non-100% zoom levels.
For bootstrap 5, if the switch/checkbox is not styled, add appearance in your css file.
For example:
.form-switch, .form-check {
.form-check-input {
-webkit-appearance: none;
-moz-appearance: none;
}
}

CSS only radio buttons not being checked on click

CSS only, I prefer not to add any additional JS. The 2nd radio button is not being "checked" when clicked.
Here's fiddle already created.
HTML:
<div class="account-container">
<div class="form-group">
<div class="control-container clearfix">
<div class="col-md-4 radio">
<input type="radio" name="Gender" value="Mujer" checked />
<label>Mujer</label>
</div>
<div class="col-md-4 radio">
<input type="radio" name="Gender" value="Hombre" />
<label>Hombre</label>
</div>
</div>
</div>
</div>
CSS:
.account-container .radio {
height: 100%;
margin: 0;
}
.account-container .radio label {
position: relative;
line-height: 40px;
cursor: pointer;
padding-left: 30px;
}
.account-container .radio label:before {
content: " ";
display: inline-block;
width: 22px;
height: 22px;
position: absolute;
left: 0;
top: 9px;
border: 1px solid #1fb5e1;
background-color: #fff;
border-radius: 50%;
}
.account-container .radio input[type="radio"]:checked + label:after {
background-color: #1fb5e1;
width: 14px;
height: 14px;
border-radius: 50%;
position: absolute;
content: " ";
left: 5px;
top: 14px;
}
<input type="radio" id="id_of_radio">
<label for="id_of_radio">
The issue is the position of your radio items, since they are not visible, you cannot click on it.
You should use the capability of the label, when you click on it, the bounded element is selected.
http://jsfiddle.net/fvzegu6o/1/
<div class="col-md-4 radio">
<input type="radio" name="Gender" value="Mujer" id="mujer" checked />
<label for="mujer">Mujer</label>
</div>
<div class="col-md-4 radio">
<input type="radio" name="Gender" value="Hombre" id="hombre" />
<label for="hombre">Hombre </label>
</div>

How can I customize css for radio buttons

I would like to replace the default view of radio buttons by customizing it. So, I would like to toggle between two images(as I am not good with css3 animations, so i chose to do the job with images).
So for check state I would like to display (check.png):
And when the radio button is unchecked I would like to display (uncheck.png):
HTML CODE:
currently I am using the following bootstrap markup:
<section class="lineHeight">
<div class="radio">
<label>
<input type="radio" name="auditTool" id="optionsRadios1" value="option1">
<span class="outer"><span class="inner"></span></span>Large
</label>
</div>
</section>
CSS:
.lineHeight{
line-height:56px;
}
.lineHeight .radio input[type=radio]{
position: absolute;
top: 50%;
margin-top: -6px;
margin-left: -20px;
}
You can hide the native radio and display a custom one with CSS.
input[type=radio] {
display: none;
}
input[type=radio] + label:before {
content: '';
display: inline-block;
border: 2px solid #0F81D5;
height: 12px;
width: 12px;
border-radius: 50%;
}
label:hover:before {
box-shadow: inset 0 0 5px orange;
}
input[type=radio]:checked + label:before {
border-width: 5px;
height: 6px;
width: 6px;
}
<div>
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Foo</label>
</div>
<div>
<input type="radio" name="radio" id="radio2" />
<label for="radio2">Bar</label>
</div>
<div>
<input type="radio" name="radio" id="radio3" />
<label for="radio3">Baz</label>
</div>
input[type=radio].css-checkbox {
position: absolute;
z-index: -1000;
left: -1000px;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0;
}
input[type=radio].css-checkbox + label.css-label {
padding-left: 23px;
height: 18px;
display: inline-block;
line-height: 18px;
background-repeat: no-repeat;
background-position: 0 0;
font-size: 18px;
vertical-align: middle;
cursor: pointer;
}
input[type=radio].css-checkbox:checked + label.css-label {
background-position: 0 -18px;
}
label.css-label {
background-image: url(http://csscheckbox.com/checkboxes/u/csscheckbox_67c83917465692304d237c7e9e0533ca.png);
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>CSS Checkbox Demo from CSSCheckbox.com</title>
<link rel="stylesheet" href="style.css" />
<style type="text/css">
/*this is just to organize the demo checkboxes*/
label {
margin-right: 20px;
}
</style>
</head>
<body>
<h1 style="margin:0; margin-top:10px; padding:0; padding-left:25px; padding-bottom:10px; font-family:sans-serif;">CSS Checkboxes!</h1>
<div style="background:#444; color:#fafafa; padding:10px;">
<h3>Dark Background</h3>
<table>
<tr>
<td>
<input type="radio" name="radiog_lite" id="radio1" class="css-checkbox" />
<label for="radio1" class="css-label radGroup1">Option 1</label>
</td>
<td>
<input type="radio" name="radiog_lite" id="radio2" class="css-checkbox" checked="checked" />
<label for="radio2" class="css-label radGroup1">Option 2</label>
</td>
<td>
<input type="radio" name="radiog_lite" id="radio3" class="css-checkbox" />
<label for="radio3" class="css-label radGroup1">Option 1</label>
</td>
</tr>
</table>
</div>
<div style="background:#fafafa; color:#222; padding:10px;">
<h3>Light Background</h3>
<table>
<tr>
<td>
<input type="radio" name="radiog_dark" id="radio4" class="css-checkbox" />
<label for="radio4" class="css-label radGroup2">Option 1</label>
</td>
<td>
<input type="radio" name="radiog_dark" id="radio5" class="css-checkbox" checked="checked" />
<label for="radio5" class="css-label radGroup2">Option 2</label>
</td>
<td>
<input type="radio" name="radiog_dark" id="radio6" class="css-checkbox" />
<label for="radio6" class="css-label radGroup2">Option 1</label>
</td>
</tr>
</table>
</div>
<p style="padding-left:25px;">Radio Button generated by CSS Checkbox
</p>
</body>
</html>
Reference: http://www.csscheckbox.com/radio-buttons/0/

Modal label elements wrapping to newline in webkit browsers

I'm currently having a problem with CSS styles in Webkit browswers (Chrome 4.0.249.89 & safari 4.0.4) in which I have a modal window that has a list of labels, radio buttons and some more text describing the what each radio button does. The modal displays correctly in FF 3.5.7
Here's the html for inside the modal,
<div id="rta_top">
<img src="pb_close_off.png" width="17" height="15" alt="Close this window" title="Close this window" id="rta_close" />
<h2 class="rta">Report</h2>
</div>
<div id="pb_bottom">
<div id="error_holder">
<div id="error"></div>
</div>
<br />
Please choose a reason for reporting this ad:
<form action="submit.php" method="post" id="report_form">
<fieldset>
<br />
<label for="incorrect_address">Wrong Address:</label>
<div class="report_ad_radio">
<input type="radio" id="incorrect_address" name="description" value="1" />
</div>
<div class="report_ad_text">
<label for="incorrect_address"> (Ad has wrong address).</label>
</div>
<br />
<label for="duplicate">Duplicate:</label>
<div class="report_ad_radio">
<input type="radio" id="duplicate" name="description" value="2" />
</div>
<div class="report_ad_text">
<label for="duplicate"> (Identical to another ad on-site).</label>
</div>
<br />
<label for="mis_classified">Mis-Classified:</label>
<div class="report_ad_radio">
<input type="radio" id="mis_classified" name="description" value="3" />
</div>
<div class="report_ad_text">
<label for="mis_classified"> (Ad is in the wrong section).</label>
</div>
<br />
<label for="inaccurate">Inaccurate:</label>
<div class="report_ad_radio">
<input type="radio" id="inaccurate" name="description" value="4" />
</div>
<div class="report_ad_text">
<label for="inaccurate"> (No longer available / price changed).</label>
</div>
<br />
<label for="photos">Photo Issue:</label>
<div class="report_ad_radio">
<input type="radio" id="photos" name="description" value="5" />
</div>
<div class="report_ad_text">
<label for="photos"> (Photos are inappropriate or do not belong to this ad).</label>
</div>
<br />
<label for="spam">Spam:</label>
<div class="report_ad_radio">
<input type="radio" id="spam" name="description" value="6" />
</div>
<div class="report_ad_text">
<label for="spam"> (Ad is spam/scam and is not exclusive).</label>
</div>
<br />
<label for="other">Other:</label>
<div class="report_ad_radio">
<input type="radio" id="other" name="description" value="7" />
</div>
<div class="report_ad_text">
<label for="other"> (Other reason, please specify).</label>
</div>
<br />
<br />
<label for="more_info">More Info:</label>
<textarea id="information" name="information"></textarea>
<br />
<br />
<div id="sending">
<div id="loader"></div>
<input type="hidden" name="submit_report_ad" value="1" />
<input type="image" src="/i/button_send_off.png" id="reply_button" name="submit_reply" value="Send ยป" />
</div>
</fieldset>
</div>
</div>
and the css for each element:
#rta_background {
padding: 10px;
background: url(/i/bg_modal_ra.png) no-repeat;
}
#ra_background_sent{
padding: 10px;
background: url(/i/bg_modal_ra_sent.png) no-repeat;
}
#rta_top {
padding: 0 8px 0 18px;
background: #355eae url(/i/bg_linkbar_off.png) repeat-x;
height: 30px;
line-height: 30px;
}
#rta_top h2 {
overflow: hidden;
width: 495px;
height: 30px;
font-size: 14px;
color: #fff;
}
#rta_close {
margin: 7px 0 0;
float: right;
}
#rta #pb_bottom fieldset {
background: #dff;
}
.report_ad_radio {
padding: 5px 0 0 5px;
float: left;
}
#rta #pb_bottom .rta_warning {
margin: 0 auto 6px;
border: 1px solid #f00;
padding: 2px 0;
width: 80%;
height: 15px;
line-height: 15px;
font-size: 12px;
font-weight: bold;
color: #000;
text-align: center;
background: #fdd;
}
#rta #pb_bottom .report_ad_text {
white-space: nowrap;
}
#rta #pb_bottom .report_ad_text label {
margin: 0;
padding: 10px 0 0 0;
width: auto;
font-size: 12px;
font-weight: normal;
cursor: pointer;
background: #00f000;
}
#information {
margin: 5px 0 0 5px;
padding: 2px 2px 2px 2px;
width: 370px;
height: 76px;
border: 1px solid #ccc;
color: #888;
line-height: 1.4;
resize: none;
}
#sending {
float:right;
margin-right: 24px;
}
#pb_bottom #error {
margin: 0 20px 0 50px;
height: 20px;
width: 420px;
}
#loader {
margin-right: 20px;
margin-top: 6px;
float:left;
}
In Safari it looks like this:
Safari http://neilcremins.com/img_dump/modal-saf.png
In Firefox it looks like this:
Firefox http://neilcremins.com/img_dump/modal-ff.png
Wow. Div-soup with everything defined in absolute measures. I don't know where to start. I know, I'll start here: you can only have one label per input, so... let's try this:
HTML:
<label><span class="intro">Wrong address</span><input type="radio" id="wrongaddress"/>(Ad has wrong address)</label>
CSS:
label{display: block}
.intro{width: 12em; float: left; font-weight: bold}
Demo.
Less is more.

Resources