Floating list issue - html

I am creating a list with 5 star rating. I want to put stars in from of list title but my stars are not showing in front of list title.
.cont {
color: #eee;
margin: 0 auto;
max-width: 350px;
overflow: hidden;
padding: 0;
text-align: center;
width: 100%;
}
hr {
margin: 20px;
border: none;
border-bottom: thin solid rgba(255, 255, 255, .1);
}
div.stars {
width: 270px;
display: inline-block;
float: left;
}
input.star {
display: none;
}
label.star {
color: #444;
float: right;
font-size: 25px;
padding: 5px;
transition: all .2s;
}
input.star:checked ~ label.star:before {
content: '\f005';
color: #FD4;
transition: all .25s;
}
input.star-5:checked ~ label.star:before {
color: #FE7;
text-shadow: 0 0 20px #952;
}
input.star-1:checked ~ label.star:before {
color: #F62;
}
label.star:hover {
transform: rotate(-15deg) scale(1.3);
}
label.star:before {
content: '\f006';
font-family: FontAwesome;
}
/* LIST #3 */
#list3 {
float: left;
}
#list3 ul {
list-style-image: url("../images/arrow.png");
color: #4B4B4B;
font-size: 18px;
margin-left: 25px;
}
#list3 ul li {
line-height: 30px;
}
<div id="list3">
<ul>
<li>Estimated time: 43min</li>
<li>Distance in miles: 14 miles</li>
<li>Review Rating:
<div class="cont">
<div class="stars">
<form action="">
<input class="star star-5" id="star-5-2" type="radio" name="star" />
<label class="star star-5" for="star-5-2"></label>
<input class="star star-4" id="star-4-2" type="radio" name="star" />
<label class="star star-4" for="star-4-2"></label>
<input class="star star-3" id="star-3-2" type="radio" name="star" />
<label class="star star-3" for="star-3-2"></label>
<input class="star star-2" id="star-2-2" type="radio" name="star" />
<label class="star star-2" for="star-2-2"></label>
<input class="star star-1" id="star-1-2" type="radio" name="star" />
<label class="star star-1" for="star-1-2"></label>
</form>
</div>
</div>
</li>
</ul>
</div>

Try this: http://codepen.io/g1un/pen/KgvrwZ
.cont {
color: #eee;
margin: 0 auto;
max-width: 350px;
overflow: hidden;
padding: 0;
text-align: center;
/* width: 100%; */
display: inline-block;
vertical-align: top;
}
div.stars {
/* width: 270px; */
display: inline-block;
/* float: left; */
}
Your main mistake causing appearing of your rating icons below the title is that rating block has display: block; property by default as a div and you didn't change it.
It is also no need in width: 100% that causes element jumping to another row to fit this property.

Related

Custom radio button not getting checked on clicking

I created a custom radio button using HTML and CSS
.radio {
display: inline-flex;
align-items: center;
cursor: pointer;
margin-left: 10px;
}
.radio__input {
display: none;
}
.radio__radio {
width: 1.25em;
height: 1.25em;
border: 2px solid #87cac3;
border-radius: 50%;
margin-left: 10px;
box-sizing: border-box;
padding: 2px;
}
.radio__radio::after {
content: "";
width: 100%;
height: 100%;
display: block;
background: #87cac3;
border-radius: 50%;
transform: scale(0);
transition: transform 0.15s;
}
.radio__input:checked+.radio__radio::after {
transform: scale(1)
}
<div>
<label for="myRadioId" class="radio">Agree</label>
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input">
<div class="radio__radio"></div>
</label>
</div>
The code doesn't seem to work accurately means, the radio button is not getting checked on clicking. I think the problem is with the .radio__radio::after inside it i have done trnsform: scale(0) so it should default change its scale to zero on refreshing the page and when checked it should change the scale to 1.
Use the following code, hope it will be helpful .
var val = 0;
$('input[name=myRadioField]').on("click", function(){
console.log(val);
if($(this).val()==val)
{$(this).prop('checked', false);
val = -1;
}
else val = $(this).val();
});
.radio {
display: inline-flex;
align-items: center;
cursor: pointer;
margin-left: 10px;
}
.radio__input {
display: none;
}
.radio__radio {
width: 1.25em;
height: 1.25em;
border: 2px solid #87cac3;
border-radius: 50%;
margin-left: 10px;
box-sizing: border-box;
padding: 2px;
}
.radio__radio::after {
content: "";
width: 100%;
height: 100%;
display: block;
background: #87cac3;
border-radius: 50%;
transform: scale(0);
transition: transform 0.15s;
}
.radio__input:checked+.radio__radio::after {
transform: scale(1)
}
.radio__input:unchecked+.radio__radio::after {
transform: scale(0)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div>
<label for="myRadioId" class="radio">Agree
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input">
<div class="radio__radio"></div>
</label>
</div>
Thanks everyone for your inputs.
The problem is solved I just added autocomplete= "off" inside <input> tag and it worked fine.
.container {
padding-top: 10px;
text-align: center;
}
.radio {
display: inline-flex;
align-items: center;
cursor: pointer;
margin-left: 10px;
}
.radio__input {
display: none;
}
.radio__radio {
width: 1.25em;
height: 1.25em;
border: 2px solid #87cac3;
border-radius: 50%;
margin-left: 10px;
box-sizing: border-box;
padding: 2px;
padding-bottom: 2px;
}
.radio__radio::after {
content: "";
width: 100%;
height: 100%;
display: block;
background: #87cac3;
border-radius: 50%;
transform: scale(0);
transition: transform 0.15s;
}
.radio__input:checked+.radio__radio::after {
transform: scale(1)
}
<div class="container">
<h1>Question 1</h1>
<h4>Agree
<label class="radio">
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input" autocomplete="off" value="1">
<div class="radio__radio"></div>
</label>
<label class="radio">
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input" autocomplete="off" value="2">
<div class="radio__radio"></div>
</label>
<label class="radio">
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input" autocomplete="off" value="3">
<div class="radio__radio"></div>
</label>
<label class="radio">
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input" autocomplete="off" value="4">
<div class="radio__radio"></div>
</label>
<label class="radio">
<input type="radio" name="myRadioField" id="myRadioId" class="radio__input" autocomplete="off" value="5">
<div class="radio__radio"></div>
</label> Disagree
</h4>
</div>

CSS Radio section not stacking on top properly?

I'm trying to stack my radio button labels on top of each other with the radio button option on right of the label
Here is my HTML
<p>Instagram destorys the younger generation:</p>
<div class="instagram">
<input type="radio" name="instagram" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="instagram" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="instagram" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br>
<br>
</div>
Here is my CSS
/* the styles for the elements */
body {
font-family: Arial, Helvetica, sans-serif;
width: 900px;
margin: 0 auto;
padding: 0;
box-shadow: 0 10px 20px 10px;
}
h1, h2, h3, p {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
font-weight: bold;
}
a:hover, a:focus {
color: maroon;
}
/* the styles for the header */
header {
border-bottom: 3px solid #FFD300;
background-image: -moz-linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -webkit-linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -o-linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #00000080 80%, #2641B3 100%);
padding: 15px 30px;
}
header img {
float: left;
}
header h2 {
font-size: 250%;
font-style: italic;
color: steelblue;
text-indent: 45px;
text-shadow: 3px 3px 3px steelblue;
margin-bottom: .3em;
}
header h3 {
font-size: 150%;
text-indent: 45px;
padding-bottom: .75em;
}
/* the styles for the navigation menu */
#nav_menu {
clear: left;
}
#nav_menu ul {
list-style: none;
position: relative;
display: flex;
justify-content: space-evenly;
}
#nav_menu ul li {
float: left;
}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li {
float: none;
}
#nav_menu ul li:hover > ul {
display: block;
}
#nav_menu > ul::after {
content: "";
clear: both;
display: block;
}
#nav_menu ul {
margin: 0;
padding: 0;
}
#nav_menu ul li a {
text-align: center;
display: block;
width: 180px;
padding: .7em 0;
font-weight: bold;
color: white;
}
#nav_menu ul li a.current {
color: black;
}
#nav_menu ul li a:hover, #nav_menu ul li a:focus {
background-color: lightsteelblue;
}
/* the styles for the section */
section {
width: 565px;
float: right;
padding: 25px 30px;
}
section h1 {
font-size: 160%;
margin-bottom: .3em;
}
section p {
font-size: 100%;
margin-bottom: .7em;
}
/*thestyle for the form*/
fieldset {
margin-bottom: .5em;
padding: .5em 1em;
}
fieldset p {
font-size: 90%;
margin-bottom: .5em;
}
legend {
font-weight: bold;
font-size: 90%;
padding-bottom: .9em;
}
label, input, select {
font-size: 90%;
}
label {
display: block;
width: 9em;
text-align: right;
}
input, select {
width: 15em;
margin-left: .5em;
margin-bottom: .7em;
}
input:required, input[required] input:invalid
{
border: 2px solid maroon;
}
input:valid {
border: 1px solid black;
}
input:invalid {
box-shadow: none;
}
br {
clear: both;
}
#buttons input {
width: 10em;
}
textarea {
height: 10em;
width: 40em;
margin-left: 2.5em;
font-family: Arial, Helvetica, sans-serif;
}
#lifestyle label, #food label, #comments label {
float: none;
}
#lifestyle input, #food input {
width: auto;
margin-left: 3em;
}
#buttons input {
width: 10em;
}
#submit {
margin-left: 3em;
}
/* the styles for the sidebar */
aside {
float: left;
width: 245px;
padding: 25px 0 0 30px;
}
aside h2 {
font-size: 130%;
color: maroon;
margin-bottom: 8px;
}
aside ul {
line-height: 1.5;
margin: 0;
padding-left: 16px;
}
aside a:link, aside a:visited {
color: steelblue;
}
aside a:hover, aside a:focus {
color: maroon;
}
/* the styles for the footer */
footer {
clear: both;
padding: 15px 30px;
background-color: steelblue;
}
footer p {
text-align: center;
font-size: 85%;
color: white;
}
.instagram, #agree {
display: inline;
justify-content: flex-start;
text-align: left;
width: 1rem;
}
The full HTML is below
<main>
<section>
<h1>Opinion about Social Media</h1>
<p>Please answer the questions honestly!</p>
<form action="opinion_request.html" method="get" id="opinions_form">
<fieldset>
<legend>Please try to answer every question</legend><br><br>
<label for="name">Full name:</label>
<input type="text" id="name" autofocus required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" required><br><br>
<label for="gender">Gender:</label>
<select id="gender">
<option value="none">Select a Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select><br><br>
<label>How many hrs per day do you use Social Media?:</label>
<select id="age">
<option value="none">Select your choice</option>
<option value="1-2hrsr">1-2hrs</option>
<option value="2-4hrs">2-4hrs</option>
<option value="5hrs+">5hrs+</option>
</select><br><br>
<label for="social">List 2 social medias that you use the most:</label>
<input type="text" id="social" placeholder="Example: Instagram, Twitter, Facebook"><br><br>
<label for="rate">Rate Twitter from 1 to 5:</label>
<input type="range" id="rate"
min="1" max="5" step="1"><br><br>
</fieldset>
<fieldset>
<legend>Survey</legend><br>
Date you first started social media:
<input type="date" id="date"><br><br>
<p>Instagram destorys the younger generation:</p>
<div class="instagram">
<input type="radio" name="instagram" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="instagram" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="instagram" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br>
<br>
</div>
<p>Linkedin is the best networking social media:</p>
<input type="radio" name="link" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="link" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="link" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br><br>
<p>Tiktok is the next big social media:</p>
<input type="radio" name="tiktok" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="tiktok" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="tiktok" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br><br>
<p>Facebook is the most popular social media:</p>
<input type="radio" name="fb" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="social" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br><br>
</fieldset>
<fieldset><br>
<legend>Comments:</legend>
<p>In 10 years do you think you'll still use social media? Why or why not?</p>
<textarea id="text-area">
</textarea>
</fieldset>
<br>
<fieldset id="buttons">
<legend>Process your information</legend><br>
<input type="submit" id="submit" value="Submit now">
<input type="reset" id="submit" value="start over">
</fieldset>
</form>
</section>
</main>
Here are pics of what it currently looks like and how I want it to look like
You can add some css rules to achieve the desired result. Add the following css rules.
#opinions_form input[type=radio]~label::after {
height: 1px;
width: 100%;
display: block;
content: '';
}
And remove display:block rule in label selector. Change it to following.
label {
width: 9em;
text-align: right;
}
Check this codepen link.
https://codepen.io/aryantw/pen/vYNOWOL
I made couple div around, reason it makes it clean and consistent across the options. important thing is used flex so that it makes the items inline, hope it works for you:
body {
font-family: Arial, Helvetica, sans-serif;
width: 900px;
margin: 0;
padding: 0;
border: 0;
box-shadow: 0 10px 20px 10px;
}
h1,
h2,
h3,
p {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
font-weight: bold;
}
a:hover,
a:focus {
color: maroon;
}
/* the styles for the header */
header {
border-bottom: 3px solid #FFD300;
background-image: -moz-linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -webkit-linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -o-linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #00000080 80%, #2641B3 100%);
padding: 15px 30px;
}
header img {
float: left;
}
header h2 {
font-size: 250%;
font-style: italic;
color: steelblue;
text-indent: 45px;
text-shadow: 3px 3px 3px steelblue;
margin-bottom: .3em;
}
header h3 {
font-size: 150%;
text-indent: 45px;
padding-bottom: .75em;
}
/* the styles for the navigation menu */
#nav_menu {
clear: left;
}
#nav_menu ul {
list-style: none;
position: relative;
display: flex;
justify-content: space-evenly;
}
#nav_menu ul li {
float: left;
}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li {
float: none;
}
#nav_menu ul li:hover>ul {
display: block;
}
#nav_menu>ul::after {
content: "";
clear: both;
display: block;
}
#nav_menu ul {
margin: 0;
padding: 0;
}
#nav_menu ul li a {
text-align: center;
display: block;
width: 180px;
padding: .7em 0;
font-weight: bold;
color: white;
}
#nav_menu ul li a.current {
color: black;
}
#nav_menu ul li a:hover,
#nav_menu ul li a:focus {
background-color: lightsteelblue;
}
/* the styles for the section */
section {
width: 565px;
float: right;
padding: 25px 30px;
}
section h1 {
font-size: 160%;
margin-bottom: .3em;
}
section p {
font-size: 100%;
margin-bottom: .7em;
}
/*thestyle for the form*/
fieldset {
margin-bottom: .5em;
padding: .5em 1em;
}
fieldset p {
font-size: 90%;
margin-bottom: .5em;
}
legend {
font-weight: bold;
font-size: 90%;
padding-bottom: .9em;
}
label,
input,
select {
font-size: 90%;
}
label {
display: block;
width: 9em;
text-align: right;
}
select {
width: 15em;
margin-left: .5em;
margin-bottom: .7em;
}
input:required,
input[required] input:invalid {
border: 2px solid maroon;
}
input:valid {
border: 1px solid black;
}
input:invalid {
box-shadow: none;
}
br {
clear: both;
}
#buttons input {
width: 10em;
}
textarea {
height: 10em;
width: 40em;
margin-left: 2.5em;
font-family: Arial, Helvetica, sans-serif;
}
#lifestyle label,
#food label,
#comments label {
float: none;
}
#lifestyle input,
#food input {
width: auto;
margin-left: 3em;
}
#buttons input {
width: 10em;
}
#submit {
margin-left: 3em;
}
/* the styles for the sidebar */
aside {
float: left;
width: 245px;
padding: 25px 0 0 30px;
}
aside h2 {
font-size: 130%;
color: maroon;
margin-bottom: 8px;
}
aside ul {
line-height: 1.5;
margin: 0;
padding-left: 16px;
}
aside a:link,
aside a:visited {
color: steelblue;
}
aside a:hover,
aside a:focus {
color: maroon;
}
/* the styles for the footer */
footer {
clear: both;
padding: 15px 30px;
background-color: steelblue;
}
footer p {
text-align: center;
font-size: 85%;
color: white;
}
.instagram,
.facebook,
.tiktok,
.linkedin {
justify-content: space-between;
text-align: center;
width: auto;
margin-left: 15%;
}
.opinioncolumn {
display: flex;
flex-direction: column;
}
.opinionRow {
display: flex;
}
<main>
<section>
<h1>Opinion about Social Media</h1>
<p>Please answer the questions honestly!</p>
<form action="opinion_request.html" method="get" id="opinions_form">
<fieldset>
<legend>Please try to answer every question</legend><br><br>
<label for="name">Full name:</label>
<input type="text" id="name" autofocus required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" required><br><br>
<label for="gender">Gender:</label>
<select id="gender">
<option value="none">Select a Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select><br><br>
<label>How many hrs per day do you use Social Media?:</label>
<select id="age">
<option value="none">Select your choice</option>
<option value="1-2hrsr">1-2hrs</option>
<option value="2-4hrs">2-4hrs</option>
<option value="5hrs+">5hrs+</option>
</select><br><br>
<label for="social">List 2 social medias that you use the most:</label>
<input type="text" id="social" placeholder="Example: Instagram, Twitter, Facebook"><br><br>
<label for="rate">Rate Twitter from 1 to 5:</label>
<input type="range" id="rate" min="1" max="5" step="1"><br><br>
</fieldset>
<fieldset>
<legend>Survey</legend><br> Date you first started social media:
<input type="date" id="date"><br><br>
<p>Instagram destorys the younger generation:</p>
<div class="instagram">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="instagram" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="instagram" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label><br>
<input type="radio" name="instagram" value="strongly" id="agree">
</div>
</div>
<br>
</div>
<p>Linkedin is the best networking social media:</p>
<div class="linkedin">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="link" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="link" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label>
<input type="radio" name="link" value="strongly" id="agree">
<br><br>
</div>
</div>
<br>
</div>
<p>Tiktok is the next big social media:</p>
<div class="tiktok">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="tiktok" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="tiktok" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label>
<input type="radio" name="tiktok" value="strongly" id="agree">
<br><br>
</div>
</div>
</div>
<p>Facebook is the most popular social media:</p>
<div class="facebook">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="fb" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label><br><br>
<input type="radio" name="social" value="strongly" id="agree">
</div>
</div>
</div>
</fieldset>
<fieldset><br>
<legend>Comments:</legend>
<p>In 10 years do you think you'll still use social media? Why or why not?</p>
<textarea id="text-area">
</textarea>
</fieldset>
<br>
<fieldset id="buttons">
<legend>Process your information</legend><br>
<input type="submit" id="submit" value="Submit now">
<input type="reset" id="submit" value="start over">
</fieldset>
</form>
</section>
</main>

How to make radio button like on/off switches using css

I have requirement of radio buttons with on/off method i.e when click on one radio button it should on and when click on second button first button should off but below code is not working as per my expectation.
Here is the snippet for that html and css code:
body {
background: #0288D1;
}
.checkboxes-and-radios {
margin: 80px auto 0;
width: 280px;
padding: 30px;
background: #fafafa;
input {
display: none;
}
label {
cursor: pointer;
padding-right: 35px;
position: relative;
display: block;
font-size: 18px;
padding: 15px 0
}
input[type="checkbox"],
input[type="radio"] {
position: absolute;
visibility: hidden !important;
}
input[type="checkbox"]+label,
input[type="radio"]+label {
&:before,
&:after {
content: '';
position: absolute;
top: 50%;
margin-top: -7.5px;
box-sizing: border-box;
}
&:before {
width: 30px;
height: 15px;
right: 0px;
background: #fff;
border: 1px solid #e4e3e1;
border-radius: 15px;
}
&:after {
width: 15px;
height: 15px;
right: 15px;
background: #BDBDBD;
border-radius: 50%;
transition: all 200ms ease-out;
}
}
input[type="checkbox"]:checked+label,
input[type="radio"]:checked+label {
&:after {
right: 0px;
background: #FF9800;
}
}
}
<div class="checkboxes-and-radios">
<h1>Radios:</h1>
<input type="radio" name="radio-cats" id="radio-1" value="1" checked>
<label for="radio-1">Radio Label 1</label>
<input type="radio" name="radio-cats" id="radio-2" value="2">
<label for="radio-2">Radio Label 2</label>
<input type="radio" name="radio-cats" id="radio-3" value="3" checked>
<label for="radio-3">Radio Label 3</label>
<h1>Checkboxes:</h1>
<input type="checkbox" name="checkbox-cats[]" id="checkbox-1" value="1" checked>
<label for="checkbox-1">Checkbox Label 1</label>
<input type="checkbox" name="checkbox-cats[]" id="checkbox-2" value="2">
<label for="checkbox-2">Checkbox Label 2</label>
<input type="checkbox" name="checkbox-cats[]" id="checkbox-3" value="3" checked>
<label for="checkbox-3">Checkbox Label 3</label>
</div>
expected output:
so how to add css that will look like in image shown in top?
Your code works like a charm for me. In your provided fiddle, the SCSS was not compiled to CSS. Here a compiled version. Radio buttons are switching correctly.
Here also a version on CodePen.
Your CSS is not CSS but SCSS, which has to be compiled to CSS.
You have to use a preprocessor to compile scss to css. You should start reading here:
http://sass-lang.com
body {
background: #0288D1;
}
.checkboxes-and-radios {
margin: 80px auto 0;
width: 280px;
padding: 30px;
background: #fafafa;
}
.checkboxes-and-radios input {
display: none;
}
.checkboxes-and-radios label {
cursor: pointer;
padding-right: 35px;
position: relative;
display: block;
font-size: 18px;
padding: 15px 0;
}
.checkboxes-and-radios input[type="checkbox"],
.checkboxes-and-radios input[type="radio"] {
position: absolute;
visibility: hidden !important;
}
.checkboxes-and-radios input[type="checkbox"]+label:before,
.checkboxes-and-radios input[type="checkbox"]+label:after,
.checkboxes-and-radios input[type="radio"]+label:before,
.checkboxes-and-radios input[type="radio"]+label:after {
content: '';
position: absolute;
top: 50%;
margin-top: -7.5px;
box-sizing: border-box;
}
.checkboxes-and-radios input[type="checkbox"]+label:before,
.checkboxes-and-radios input[type="radio"]+label:before {
width: 30px;
height: 15px;
right: 0px;
background: #fff;
border: 1px solid #e4e3e1;
border-radius: 15px;
}
.checkboxes-and-radios input[type="checkbox"]+label:after,
.checkboxes-and-radios input[type="radio"]+label:after {
width: 15px;
height: 15px;
right: 15px;
background: #BDBDBD;
border-radius: 50%;
transition: all 200ms ease-out;
}
.checkboxes-and-radios input[type="checkbox"]:checked+label:after,
.checkboxes-and-radios input[type="radio"]:checked+label:after {
right: 0px;
background: #FF9800;
}
<div class="checkboxes-and-radios">
<h1>Radios:</h1>
<input type="radio" name="radio-cats" id="radio-1" value="1" checked>
<label for="radio-1">Radio Label 1</label>
<input type="radio" name="radio-cats" id="radio-2" value="2">
<label for="radio-2">Radio Label 2</label>
<input type="radio" name="radio-cats" id="radio-3" value="3" checked>
<label for="radio-3">Radio Label 3</label>
<h1>Checkboxes:</h1>
<input type="checkbox" name="checkbox-cats1" id="checkbox-1" value="1" checked>
<label for="checkbox-1">Checkbox Label 1</label>
<input type="checkbox" name="checkbox-cats2" id="checkbox-2" value="2">
<label for="checkbox-2">Checkbox Label 2</label>
<input type="checkbox" name="checkbox-cats3" id="checkbox-3" value="3" checked>
<label for="checkbox-3">Checkbox Label 3</label>
</div>

Why is my other checkbox panel going missing in this weird custom checkbox issue?

The fiddle is here.
Should be like this, in essence.
But in my custom checkbox, as you'll see in fiddle, it shows like this.
Note there are two inputs in checkgroup before a label
HTML
<div class=" text-left"><span class="font-weight-bold">Include</span> <span class="font-weight-bold">Exclude</span>
<div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="Chicken"> <input type="checkbox" class="exclude"> <label>
Chicken
</label></div>
</div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="Turkey"> <input type="checkbox" class="exclude"> <label>
Turkey
</label></div>
</div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="Beef"> <input type="checkbox" class="exclude"> <label>
Beef
</label></div>
</div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="Pork"> <input type="checkbox" class="exclude"> <label>
Pork
</label></div>
</div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="Fish"> <input type="checkbox" class="exclude"> <label>
Fish
</label></div>
</div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="No Meat - Vegetarian Only"> <input type="checkbox" class="exclude"> <label>
No Meat - Vegetarian Only
</label></div>
</div>
<div>
<div class="checkGroup"><input type="checkbox" class="include" value="No Meat - Vegan Only"> <input type="checkbox" class="exclude"> <label>
No Meat - Vegan Only
</label></div>
</div>
</div>
</div>
CSS
.checkGroup {
display: inline;
.exclude {
margin-left: 2em;
}
.include {
margin-left: 2em;
}
label {
margin-left: 2em;
}
/* Base for label styling */
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
position: absolute;
left: -9999px;
}
[type="checkbox"]:not(:checked)+label,
[type="checkbox"]:checked+label {
position: relative;
padding-left: 1.95em;
cursor: pointer;
}
/* checkbox aspect */
[type="checkbox"]:not(:checked)+label:before,
[type="checkbox"]:checked+label:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 1.25em;
height: 1.25em;
border: 2px solid #ccc;
background: #fff;
border-radius: 4px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
/* checked mark aspect */
[type="checkbox"]:not(:checked)+label:after,
[type="checkbox"]:checked+label:after {
content: '✔';
position: absolute;
top: .2em;
left: .275em;
font-size: 1.4em;
line-height: 0.8;
color: #09ad7e;
transition: all .2s;
font-family: Helvetica, Arial, sans-serif;
}
/* checked mark aspect changes */
[type="checkbox"]:not(:checked)+label:after {
opacity: 0;
transform: scale(0);
}
[type="checkbox"]:checked+label:after {
opacity: 1;
transform: scale(1);
}
/* disabled checkbox */
[type="checkbox"]:disabled:not(:checked)+label:before,
[type="checkbox"]:disabled:checked+label:before {
box-shadow: none;
border-color: #bbb;
background-color: #ddd;
}
[type="checkbox"]:disabled:checked+label:after {
color: #999;
}
[type="checkbox"]:disabled+label {
color: #aaa;
}
}
Here's the principle:
.checkGroup {
display: inline-flex;
align-items: center;
cursor: pointer;
}
.checkGroup [type=checkbox] {
visibility: hidden;
position: absolute;
}
cbox-image {
position: relative;
height: 1em;
width: 1em;
margin: 0 .35em;
display: inline-flex;
align-items: center;
justify-content: center;
border: 2px solid #eee;
border-radius: 5px;
}
.checkGroup input:checked + cbox-image:after,
.checkGroup input + cbox-image + cbox-image:after { /* checked state */
content: '✔';
position: absolute;
font-size: 1.4em;
line-height: 0.8;
color: #09ad7e;
font-family: Helvetica, Arial, sans-serif;
}
.checkGroup input:checked + cbox-image + cbox-image:after,
.checkGroup input:not(:checked) + cbox-image:after { /* unchecked state */
content: none;
}
<label class="checkGroup">
<input type="checkbox" value="Turkey">
<cbox-image></cbox-image>
<cbox-image></cbox-image> Turkey
</label>
From your comments and chats, clicking <label> should not trigger any checkbox clicks.
Therefore your original CSS is basically useless because:
You have only 1 label for 2 checkboxes.
All your CSS is styling the 1 label as if there is 2 labels.
For example, this line:
[type="checkbox"]:not(:checked)+label,
[type="checkbox"]:checked+label {
...
}
Does nothing because there isn't enough label available for one of those [type="checkbox"], other than the fact that they are overriding each other.
Besides, your CSS code contains a lot of self-overriding CSS similar to:
[type="checkbox"]:not(:checked), [type="checkbox"]:checked {...}
Where two opposite states use the same styling. It can be simplified to just
[type="checkbox"] {...}
Suggested Solution
You can transfer most styling from label to the [type="checkbox"] and [type="checkbox"]:checked::after.
Check this fiddle.
Not exactly what you asked for, but I'm sure you can tweak it yourself.

Creating Quiz: Why is it not working in Safari

The Quiz is perfectly showing in firefox and Chrome, just Safari seems to have some issues. It instantly shows the last test instead of the first like chrome and firefox are doing. What am I doing wrong. (I am using Safari Version 8.0.2 (10600.2.5)).
body {
font-size: 100%;
background: white;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, sans-serif;
font-weight: 300; }
input[type=radio],
input[type=checkbox] {
font-size: 0.8em;
position: relative;
display: inline-block;
vertical-align: middle;
border: 0.1em solid #bbbbbb;
background: none;
padding: 0.2em;
margin: 0 0.2em;
font-family: Consolas, "Courier New", monospace;
width: 1em;
height: 1em;
box-sizing: border-box;
-webkit-appearance: none; }
input[type=radio]:focus,
input[type=checkbox]:focus {
outline: 0;
border-color: #335599; }
input[type=radio] {
border-radius: 100%;
background-clip: content-box; }
input[type=radio]:checked {
background-color: #44aacc; }
h1 {
font-size: 2em;
margin: 1em auto;
text-align: center; }
.test {
position: absolute;
top: 25%;
bottom: 25%;
right: 25%;
left: 25%;
background: white; }
.test a {
display: block;
text-align: center;
padding: 0.5em 1em;
border-radius: 3px;
text-decoration: none;
background: #666666;
color: white; }
.test a:hover {
background: #4d4d4d; }
.test .question {
font-size: 1.3em;
margin: 0.5em 0;
border-bottom: 2px dashed #666666; }
.test .answer {
display: inline-block;
padding: 0.5em 1em;
cursor: pointer;
border-bottom: 4px solid white; }
.test .answer:hover {
border-color: #bbbbbb; }
.test .test {
transform: translate3d(150%, 0, 0);
transition: transform 100ms;
top: 0;
bottom: 0;
right: 0;
left: 0; }
.test .false:checked + .answer {
border-color: #dd4411; }
.test .true:checked ~ .test {
transform: translate3d(0, 0, 0); }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="quiz_test.css" type="text/css">
<meta>
<title>test</title>
</head>
<body>
<h1>A simple Quiz in pure CSS</h1>
<div class="test">
<h3 class="question">1 + 2 = ?</h3>
<input type="radio" name="1" id="1-1" class="false"> <label for="1-1" class="answer">12</label><br>
<input type="radio" name="1" id="1-2" class="true"> <label for="1-2" class="answer">3</label>
<div class="test">
<h3 class="question">red - green, orange - blue, yellow - ?</h3>
<input type="radio" name="2" id="2-1" class="false"> <label for="2-1" class="answer">magenta</label><br>
<input type="radio" name="2" id="2-2" class="true"> <label for="2-2" class="answer">purple</label><br>
<input type="radio" name="2" id="2-3" class="false"> <label for="2-3" class="answer">cyan</label>
<div class="test">
<h3 class="question">name the fish!</h3>
<input type="radio" name="3" id="3-1" class="true"> <label for="3-1" class="answer">shark</label><br>
<input type="radio" name="3" id="3-2" class="false"> <label for="3-2" class="answer">dolphin</label><br>
<input type="radio" name="3" id="3-3" class="false"> <label for="3-3" class="answer">whale</label><br>
<input type="radio" name="3" id="3-4" class="false"> <label for="3-4" class="answer">all of the above</label>
<div class="test">
<h1>YOU WIN!!!</h1>
play again
</div>
</div>
</div>
</div>
</body>
</html>
The Problem is that webkit doesnt understand the transition and transform attributes without vendor prefixes. Copy every line of transition and transform and replace the duplicate with -webkit-transision and -webkit- transform.
body {
font-size: 100%;
background: white;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, sans-serif;
font-weight: 300; }
input[type=radio],
input[type=checkbox] {
font-size: 0.8em;
position: relative;
display: inline-block;
vertical-align: middle;
border: 0.1em solid #bbbbbb;
background: none;
padding: 0.2em;
margin: 0 0.2em;
font-family: Consolas, "Courier New", monospace;
width: 1em;
height: 1em;
box-sizing: border-box;
-webkit-appearance: none; }
input[type=radio]:focus,
input[type=checkbox]:focus {
outline: 0;
border-color: #335599; }
input[type=radio] {
border-radius: 100%;
background-clip: content-box; }
input[type=radio]:checked {
background-color: #44aacc; }
h1 {
font-size: 2em;
margin: 1em auto;
text-align: center; }
.test {
position: absolute;
top: 25%;
bottom: 25%;
right: 25%;
left: 25%;
background: white; }
.test a {
display: block;
text-align: center;
padding: 0.5em 1em;
border-radius: 3px;
text-decoration: none;
background: #666666;
color: white; }
.test a:hover {
background: #4d4d4d; }
.test .question {
font-size: 1.3em;
margin: 0.5em 0;
border-bottom: 2px dashed #666666; }
.test .answer {
display: inline-block;
padding: 0.5em 1em;
cursor: pointer;
border-bottom: 4px solid white; }
.test .answer:hover {
border-color: #bbbbbb; }
.test .test {
transform: translate3d(150%, 0, 0);
transition: transform 100ms;
-webkit-transform: translate3d(150%, 0, 0);
-webkit-transition: transform 100ms;
top: 0;
bottom: 0;
right: 0;
left: 0; }
.test .false:checked + .answer {
border-color: #dd4411; }
.test .true:checked ~ .test {
transform: translate3d(0, 0, 0);
-webkit-transform: translate3d(0, 0, 0);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="quiz_test.css" type="text/css">
<meta>
<title>test</title>
</head>
<body>
<h1>A simple Quiz in pure CSS</h1>
<div class="test">
<h3 class="question">1 + 2 = ?</h3>
<input type="radio" name="1" id="1-1" class="false"> <label for="1-1" class="answer">12</label><br>
<input type="radio" name="1" id="1-2" class="true"> <label for="1-2" class="answer">3</label>
<div class="test">
<h3 class="question">red - green, orange - blue, yellow - ?</h3>
<input type="radio" name="2" id="2-1" class="false"> <label for="2-1" class="answer">magenta</label><br>
<input type="radio" name="2" id="2-2" class="true"> <label for="2-2" class="answer">purple</label><br>
<input type="radio" name="2" id="2-3" class="false"> <label for="2-3" class="answer">cyan</label>
<div class="test">
<h3 class="question">name the fish!</h3>
<input type="radio" name="3" id="3-1" class="true"> <label for="3-1" class="answer">shark</label><br>
<input type="radio" name="3" id="3-2" class="false"> <label for="3-2" class="answer">dolphin</label><br>
<input type="radio" name="3" id="3-3" class="false"> <label for="3-3" class="answer">whale</label><br>
<input type="radio" name="3" id="3-4" class="false"> <label for="3-4" class="answer">all of the above</label>
<div class="test">
<h1>YOU WIN!!!</h1>
play again
</div>
</div>
</div>
</div>
</body>
</html>
P.S. The snippet above doesn't run correctly in the preview box because some of stackoverflows css is interfering. It does however run correctly in the full page preview.