I am using this Codepen to rate a web application. In every Desktop browser it looks the same.
So the CSS looks like this:
body {
padding: 1em;
}
input {
position:absolute;
top: -2em;
clip:rect(0,0,0,0);
}
.score {
unicode-bidi: bidi-override;
direction: rtl;
text-align: center;
border: 0;
font-size: 0;
}
.score legend {
overflow: hidden;
height: 0;
}
.score label {
font-size: 80px; font-size: 9rem;
line-height: 80px; line-height: 9rem;
display: inline-block;
position: relative;
text-align: center;
width: 1.2em;
height: 1em;
overflow: hidden;
text-indent: 100%;
}
.score label:before {
content: "☆";
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
text-indent: 0;
line-height: 1em;
color: #aaa;
}
.score label:hover:before,
.score label:hover ~ label:before,
.score input:checked ~ label:before {
content: "★";
color: #ffbb04;
}
.score label:active {
position: relative;
top: 1px;
}
The HTML:
<fieldset class="score">
<legend>Score:</legend>
<input type="radio" id="score-5" name="score" value="5"/>
<label title="5 stars" for="score-5">5 stars</label>
<input type="radio" id="score-4" name="score" value="4"/>
<label title="4 stars" for="score-4">4 stars</label>
<input type="radio" id="score-3" name="score" value="3"/>
<label title="3 stars" for="score-3">3 stars</label>
<input type="radio" id="score-2" name="score" value="2"/>
<label title="2 stars" for="score-2">2 stars</label>
<input type="radio" id="score-1" name="score" value="1"/>
<label title="1 stars" for="score-1">1 stars</label>
</fieldset>
The problem: When i view this site on mobile Safari, the stars are displayed doubled, with a bit distance in between. Like this Screenshot:
Related
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>
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.
This question already has answers here:
CSS - How to Style a Selected Radio Buttons Label?
(8 answers)
Closed 4 years ago.
I have already looked on here at how to style the input buttons I found some good answers but for some reason I can not style the inside of the button when checked. Take a look at my code maybe I did something wrong
.radio input[type='radio'] {
display: none; /*removes original button*/
}
.radio label:before { /*styles outer circle*/
content: " ";
display: inline-block;
position: relative;
top: 5px;
margin: 0 5px 0 0;
width: 20px;
height: 20px;
border-radius: 11px;
border: 2px solid orange;
background-color: transparent;
}
.radio label input[type='radio']:checked + label:after { /*styles inside circle*/
border-radius: 11px;
width: 12px;
height: 12px;
position: absolute;
top: 9px;
left: 10px;
content: " ";
display: block;
background-color: blue;
}
<div class="radio">
<label><input type="radio" name="gender" value="male"> Male</label>
<label><input type="radio" name="gender" value="female"> Female</label>
<label><input type="radio" name="gender" value="other"> Other</label>
</div>
You can't go backwards in css, thats why your code doesn't work
You need to add a span inside the label after your input and you can style it when the radio is checked
see code snippet:
.radio input[type='radio'] {
display: none;
/*removes original button*/
}
.radio label:before {
/*styles outer circle*/
content: " ";
display: inline-block;
position: relative;
top: 5px;
margin: 0 5px 0 0;
width: 20px;
height: 20px;
border-radius: 11px;
border: 2px solid orange;
background-color: transparent;
}
.radio label {
position: relative;
}
.radio label input[type='radio']:checked+span {
/*styles inside circle*/
border-radius: 11px;
width: 12px;
height: 12px;
position: absolute;
top: 1px;
left: 6px;
display: block;
background-color: blue;
}
<div class="radio">
<label><input type="radio" name="gender" value="male"> Male<span></span></label>
<label><input type="radio" name="gender" value="female"> Female<span></span></label>
<label><input type="radio" name="gender" value="other"> Other<span></span></label>
</div>
Please see below.
I have put the label behind the input field and redefined the CSS for label:before when the button is checked.
You had the input field as a child of the label but in the CSS it was approached as a sibling.
input[type='radio'] {
display: none;
}
label:before {
content: " ";
display: inline-block;
position: relative;
top: 5px;
margin: 0 5px 0 0;
width: 20px;
height: 20px;
border-radius: 11px;
border: 2px solid orange;
background-color: transparent;
}
input[type='radio']:checked+label:before {
position: relative;
border: 2px solid orange;
border-radius: 11px;
width: 20px;
height: 20px;
top: 5px;
content: " ";
display: inline-block;
background-color: blue;
}
<div class="radio">
<input id="male" type="radio" name="gender" value="male">
<label for="male">Male</label>
<input id="female" type="radio" name="gender" value="female">
<label for="female">Female</label>
<input id="other" type="radio" name="gender" value="other">
<label for="other">Other</label>
</div>
So your selector is incorrect and so is your html structure. You need to move your labels after your inputs (and target the input using a for attribute on the label and id on the input), then remove the first label from your selector
I have commented the css I have changed below
.radio input[type='radio'] {
display: none; /*removes original button*/
}
.radio label { /* add this so dot is relative to the label */
position: relative;
display: inline-block;
}
.radio label:before { /*styles outer circle*/
content: " ";
display: inline-block;
top: 5px;
margin: 0 5px 0 0;
width: 20px;
height: 20px;
border-radius: 11px;
border: 2px solid orange;
background-color: transparent;
vertical-align:middle; /* add this so text is vertically centred next to ring */
}
/* remove the first label from this selector */
.radio input[type='radio']:checked + label:after { /*styles inside circle*/
border-radius: 50%;
width: 12px;
height: 12px;
position: absolute;
top: 6px; /* I have changed the top and left so this is in the centre */
left: 6px;
content: " ";
display: block;
background-color: blue;
}
<div class="radio">
<input type="radio" name="gender" value="male" id="male"><label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female"><label for="female"> Female</label>
<input type="radio" name="gender" value="other" id="other"><label for="other"> Other</label>
</div>
i have a picture with 6 individual checkboxes on my website. How i make this code responsive (ipads, phones, (..) )? i know how to make a normal picture responsive but the checkboxes in the picture mess me up.
.pic label {
max-width:100%;
}
.pic{
background: url("http://fs5.directupload.net/images/161208/alpes8ns.png") no-repeat;
width:438px;
height:496px;
position: relative;
}
p {
margin: 0em 0;
padding: 0;
}
input[type="checkbox"] {
display: none;
}
label {
cursor: pointer;
}
input[type="checkbox"] + label:before {
outline: 1px solid #color;
content: "";
display: inline-block;
font: 17px/1em sans-serif;
height: 20px;
margin: 0 .25em 0 0;
padding: 0;
vertical-align: top;
width: 30px;
}
input[type="checkbox"]:checked + label:before {
background: url("https://picload.org/image/raallapr/ffffff-0.0.png");
color: #23708F;
content: "✓";
transform: scale(2);
text-align: center;
}
input[type="checkbox"]:checked + label:after {
font-weight: bold;
}
.poin1{
left: 350px;
bottom:23px;
position: absolute;
}
.poin2{
left: 350px;
bottom:99px;
position: absolute;
}
.poin3{
left: 350px;
bottom:178px;
position: absolute;
}
.poin4{
left: 350px;
bottom:259px;
position: absolute;
}
.poin5{
left: 350px;
bottom:348px;
position: absolute;
}
.poin6{
left: 350px;
bottom:423px;
position: absolute;
}
.buttondrunter{
left: 279px;
bottom:-82px;
position: absolute;
}
<div class="pic">
<p>
<input type="checkbox" id="poin1" name="cb" class="poin1">
<label for="poin1" class="poin1"></label>
</p>
<p>
<input type="checkbox" id="poin2" name="cb" class="poin2">
<label for="poin2" class="poin2"></label>
</p>
<p>
<input type="checkbox" id="poin3" name="cb" class="poin3">
<label for="poin3" class="poin3"></label>
</p>
<p>
<input type="checkbox" id="poin4" name="cb" class="poin4">
<label for="poin4" class="poin4"></label>
</p>
<p>
<input type="checkbox" id="poin5" name="cb" class="poin5">
<label for="poin5" class="poin5"></label>
</p>
<p>
<input type="checkbox" id="poin6" name="cb" class="poin6">
<label for="poin6" class="poin6"></label>
</p>
<p style="text-align: right;" class="buttondrunter"><a class="btn primary-button" href="#">Next</a></p>
</div>
I am find out the way to create Star Rating from here
But when I implement by Intel App Framework 3.0 on Intel XDK, it's unable to vote.
My code is:
CSS and HTML:
.rating {
unicode-bidi: bidi-override;
direction: rtl;
text-align: center;
font-size: 30px;
}
.rating > span {
display: inline-block;
position: relative;
width: 1.1em;
}
.rating > span:hover,
.rating > span:hover ~ span,
.rating:not(:hover) > input:checked ~ span {
color: transparent;
}
.rating > span:hover:before,
.rating > span:hover ~ span:before,
.rating:not(:hover) > input:checked ~ span:before {
content: "\2605";
position: absolute;
left: 0;
color: gold;
}
.rating > input {
margin-left: -2.8em;
margin-right: 0;
top: 3px;
width: 2.1em;
height: 2.1em;
position: relative;
z-index: 2;
opacity: 0;
}
<div class="rating">
<input name="myrating" type="radio" value="5">
<span>☆</span>
<input name="myrating" type="radio" value="4">
<span>☆</span>
<input name="myrating" type="radio" value="3">
<span>☆</span>
<input name="myrating" type="radio" value="2">
<span>☆</span>
<input name="myrating" type="radio" value="1">
<span>☆</span>
</div>
I found in af.ui.css, input type radio would be not displayed when don't have label:
input[type="radio"],input[type="checkbox"] {display: none;}
How could I do with this?
You should be able to override the css rule by using a more specific one. I would suggest trying something like this:
.class input[type="radio"] {display: inline-block}