Radio button working in Firefox but not clickable in Chrome - html

I have created these radio buttons.
They work perfectly in Firefox, but they're not clickable in Chrome.
Here's the code:
<input type="radio" name="rating" value="1" id="radio_btn">1</input>
<input type="radio" name="rating" value="2" id="radio_btn">2</input>
<input type="radio" name="rating" value="3" id="radio_btn">3</input>
<input type="radio" name="rating" value="4" id="radio_btn">4</input>
<input type="radio" name="rating" value="5" id="radio_btn">5</input>
<input type="hidden" name="item_id" value="1" /><br/>
<input style = "margin-left:88px;margin-top:10px;" type="submit" id="sub_rating" value="Vote" />
This is the CSS:
#radio_btn {
margin-left : 3%;
margin-right : 3%;
}

As noted above, all IDs on a page must be unique.
It is better to use a class for applying styles too.
You should do something like this :
<input type="radio" name="rating" value="1" id="radio_btn1" class="radio_btn">1</input>
<input type="radio" name="rating" value="2" id="radio_btn2" class="radio_btn">2</input>
<input type="radio" name="rating" value="3" id="radio_btn3" class="radio_btn">3</input>
<input type="radio" name="rating" value="4" id="radio_btn4" class="radio_btn">4</input>
<input type="radio" name="rating" value="5" id="radio_btn5" class="radio_btn">5</input>
You'll also need to change your CSS rule to this:
.radio_btn {
margin-left : 3%;
margin-right : 3%;
}

you must for first delete </input> then change id they must not be the same and you delete the style of the submit button.
for the css you write the css code using your <form> id like this
<form id="youID">
<input type="radio" name="rating" value="1" id="radio_btn_1">1
<input type="radio" name="rating" value="2" id="radio_btn_2">2
<input type="radio" name="rating" value="3" id="radio_btn_3">3
<input type="radio" name="rating" value="4" id="radio_btn_4">4
<input type="radio" name="rating" value="5" id="radio_btn_5">5
<input type="hidden" name="item_id" value="1" /><br/>
<input type="submit" id="sub_rating" value="Vote" />
</form>
CSS
#youID input[type="radio"] {
margin-left : 3%;
margin-right : 3%;
}
#youID input[type="submit"] {
margin-left:88px;
margin-top:10px;
}

Related

How to make horizontal space between checkbox

Here is my HTML and CSS
.input[type="radio"] {
margin-left: -30px;
}
<div>
<input type="radio" name="num" value="1"><label>Label1</label>
<input type="radio" name="num" value="2"><label>Label2</label>
<input type="radio" name="num" value="3"><label>Label3</label>
<input type="radio" name="num" value="4"><label>Label4</label>
<input type="radio" name="num" value="5"><label>Label5</label>
</div>
How do I change the horizontal spacing between the radio button and the text? I'd like the text to be further to the radio button.
There you go:
The name must be the same for all radio buttons to toggle only one of them.
The class sets the right margin to 0.
And the id on the input is linked with the for attribute on the label so you can toggle the radio button by clicking the label too.
.mr0 {
margin-right: 0px;
}
<div>
<input type="radio" name="label" value="1" class="mr0" id="1"><label for="1">Label1</label>
<input type="radio" name="label" value="2" class="mr0" id="2"><label for="2">Label2</label>
<input type="radio" name="label" value="3" class="mr0" id="3"><label for="3">Label3</label>
<input type="radio" name="label" value="4" class="mr0" id="4"><label for="4">Label4</label>
<input type="radio" name="label" value="5" class="mr0" id="5"><label for="5">Label5</label>
</div>

Unable to stop a disabled checkbox from being affected by a hover event in the CSS

I have two sets of checkboxes, which act as a star rating system. One of the star ratings is disabled (by using the disabled attribute on the checkboxes), while the other one isnt.
When the user hovers over stars in the star rating system, they change colour to yellow. However if the star rating system is disabled, I do not want them to change colour when covered. I have tried to do this by using :not([disabled]) in the checkbox hover event in the CSS, but the stars still change colour on hover.
.rating,
.rating label {
margin: 0;
padding: 0;
margin-left: auto;
}
.rating {
border: none;
float: left;
}
.rating input {
display: none;
}
.rating label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating .half:before {
content: "\f089";
position: absolute;
}
.rating label {
color: #ddd;
float: right;
}
.rating input:checked~label,
/* show gold star when clicked */
.rating:not(:checked):not([disabled]) label:hover,
/* hover current star */
.rating:not(:checked) label:hover~label {
color: #FFD700;
}
/* hover current star when changing rating */
.rating input:checked~label:hover,
.rating label:hover~input:checked~label,
/* lighten current selection */
.rating input:checked~label:hover~label {
color: #FFED85;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" />
<p>This star rating system should not change colour on hover as the checkboxes are disabled</p>
<fieldset class="rating" id="93">
<input type="checkbox" id="5star_1" name="rating" value="5" disabled/>
<label class="full" for="5star_1" title="Excellent"></label>
<input type="checkbox" id="4halfstar_1" name="rating" value="4.5" disabled/>
<label class="half" for="4halfstar_1" title="Good"></label>
<input type="checkbox" id="4star_1" name="rating" value="4" disabled/>
<label class="full" for="4star_1" title="Pretty good"></label>
<input type="checkbox" id="3halfstar_1" name="rating" value="3.5" disabled/>
<label class="half" for="3halfstar_1" title="Nice"></label>
<input type="checkbox" id="3star_1" name="rating" value="3" disabled/>
<label class="full" for="3star_1" title="Ok"></label>
<input type="checkbox" id="2halfstar_1" name="rating" value="2.5" disabled/>
<label class="half" for="2halfstar_1" title="Kinda bad"></label>
<input type="checkbox" id="2star_1" name="rating" value="2" disabled/>
<label class="full" for="2star_1" title="Bad"></label>
<input type="checkbox" id="1halfstar_1" name="rating" value="1.5" disabled/>
<label class="half" for="1halfstar_1" title="Meh"></label>
<input type="checkbox" id="1star_1" name="rating" value="1" disabled/>
<label class="full" for="1star_1" title="Umm"></label>
<input type="checkbox" id="halfstar_1" name="rating" value="0.5" disabled/>
<label class="half" for="halfstar_1" title="Worst"></label>
</fieldset>
<br><br>
<p>This one does what it is supposed to (change its colour on hover)</p>
<fieldset class="rating" id="23">
<input type="checkbox" id="5star" name="rating" value="5" />
<label class="full" for="5star" title="Excellent"></label>
<input type="checkbox" id="4halfstar" name="rating" value="4.5" />
<label class="half" for="4halfstar" title="Good"></label>
<input type="checkbox" id="4star" name="rating" value="4" />
<label class="full" for="4star" title="Pretty good"></label>
<input type="checkbox" id="3halfstar" name="rating" value="3.5" />
<label class="half" for="3halfstar" title="Nice"></label>
<input type="checkbox" id="3star" name="rating" value="3" />
<label class="full" for="3star" title="Ok"></label>
<input type="checkbox" id="2halfstar" name="rating" value="2.5" />
<label class="half" for="2halfstar" title="Kinda bad"></label>
<input type="checkbox" id="2star" name="rating" value="2" />
<label class="full" for="2star" title="Bad"></label>
<input type="checkbox" id="1halfstar" name="rating" value="1.5" />
<label class="half" for="1halfstar" title="Meh"></label>
<input type="checkbox" id="1star" name="rating" value="1" />
<label class="full" for="1star" title="Umm"></label>
<input type="checkbox" id="halfstar" name="rating" value="0.5" />
<label class="half" for="halfstar" title="Worst"></label>
</fieldset>
Here is what it looks like in the developer tools with the hover state being forced on:
You are asking CSS to check if the container class has the disabled attribute (or not). You need to ask it if the input within the class has this attribute
something like:
.rating input:checked~label,
.rating input:not(:checked):not(:disabled) + label:hover,
.rating input:not(:checked):not(:disabled) + label:hover~label {
color: #FFD700;
}
Note:
You may do well to remove the first and third rules as well, and simply have the second rule apply.
Snippet:
.rating,
.rating label {
margin: 0;
padding: 0;
margin-left: auto;
}
.rating {
border: none;
float: left;
}
.rating input {
display: none;
}
.rating label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating .half:before {
content: "\f089";
position: absolute;
}
.rating label {
color: #ddd;
float: right;
}
.rating input:checked~label,
.rating input:not(:checked):not(:disabled) + label:hover,
.rating input:not(:checked):not(:disabled) + label:hover~label {
color: #FFD700;
}
.rating input:checked~label:hover,
.rating label:hover~input:checked~label,
.rating input:checked~label:hover~label {
color: #FFED85;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" />
<p>This star rating system should not change colour on hover as the checkboxes are disabled</p>
<fieldset class="rating" id="93">
<input type="checkbox" id="5star_1" name="rating" value="5" disabled/>
<label class="full" for="5star_1" title="Excellent"></label>
<input type="checkbox" id="4halfstar_1" name="rating" value="4.5" disabled/>
<label class="half" for="4halfstar_1" title="Good"></label>
<input type="checkbox" id="4star_1" name="rating" value="4" disabled/>
<label class="full" for="4star_1" title="Pretty good"></label>
<input type="checkbox" id="3halfstar_1" name="rating" value="3.5" disabled/>
<label class="half" for="3halfstar_1" title="Nice"></label>
<input type="checkbox" id="3star_1" name="rating" value="3" disabled/>
<label class="full" for="3star_1" title="Ok"></label>
<input type="checkbox" id="2halfstar_1" name="rating" value="2.5" disabled/>
<label class="half" for="2halfstar_1" title="Kinda bad"></label>
<input type="checkbox" id="2star_1" name="rating" value="2" disabled/>
<label class="full" for="2star_1" title="Bad"></label>
<input type="checkbox" id="1halfstar_1" name="rating" value="1.5" disabled/>
<label class="half" for="1halfstar_1" title="Meh"></label>
<input type="checkbox" id="1star_1" name="rating" value="1" disabled/>
<label class="full" for="1star_1" title="Umm"></label>
<input type="checkbox" id="halfstar_1" name="rating" value="0.5" disabled/>
<label class="half" for="halfstar_1" title="Worst"></label>
</fieldset>
<br><br>
<p>This one does what it is supposed to (change its colour on hover)</p>
<fieldset class="rating" id="23">
<input type="checkbox" id="5star" name="rating" value="5" />
<label class="full" for="5star" title="Excellent"></label>
<input type="checkbox" id="4halfstar" name="rating" value="4.5" />
<label class="half" for="4halfstar" title="Good"></label>
<input type="checkbox" id="4star" name="rating" value="4" />
<label class="full" for="4star" title="Pretty good"></label>
<input type="checkbox" id="3halfstar" name="rating" value="3.5" />
<label class="half" for="3halfstar" title="Nice"></label>
<input type="checkbox" id="3star" name="rating" value="3" />
<label class="full" for="3star" title="Ok"></label>
<input type="checkbox" id="2halfstar" name="rating" value="2.5" />
<label class="half" for="2halfstar" title="Kinda bad"></label>
<input type="checkbox" id="2star" name="rating" value="2" />
<label class="full" for="2star" title="Bad"></label>
<input type="checkbox" id="1halfstar" name="rating" value="1.5" />
<label class="half" for="1halfstar" title="Meh"></label>
<input type="checkbox" id="1star" name="rating" value="1" />
<label class="full" for="1star" title="Umm"></label>
<input type="checkbox" id="halfstar" name="rating" value="0.5" />
<label class="half" for="halfstar" title="Worst"></label>
</fieldset>

How to get two CSS rating star widgets to not affect each other when clicked

Thanks for taking a look...
Please see the following fiddle that shows two CSS only rating star widgets or the code below. When you select a rating on the second widget, for some reason it always changes the rating on the first widget. Any idea where the error is in my CSS? Sorry if this is a basic question, I am not very good with CSS yet. Thanks!
HTML:
<div class="stars">
<div class="rating" style="width:65%"></div>
<input type="radio" name="rating" id="star5" value="5">
<label for="star5"></label>
<input type="radio" name="rating" id="star4" value="4">
<label for="star4"></label>
<input type="radio" name="rating" id="star3" value="3">
<label for="star3"></label>
<input type="radio" name="rating" id="star2" value="2">
<label for="star2"></label>
<input type="radio" name="rating" id="star1" value="1">
<label for="star1"></label>
</div>
</br>
<div class="stars">
<div class="rating" style="width:65%"></div>
<input type="radio" name="rating" id="star5" value="5">
<label for="star5"></label>
<input type="radio" name="rating" id="star4" value="4">
<label for="star4"></label>
<input type="radio" name="rating" id="star3" value="3">
<label for="star3"></label>
<input type="radio" name="rating" id="star2" value="2">
<label for="star2"></label>
<input type="radio" name="rating" id="star1" value="1">
<label for="star1"></label>
</div>
CSS:
.stars{
width: 130px;
height: 26px;
background: url(http://sandbox.bumbu.ru/ui/external/stars.png) 0 0 repeat-x;
position: relative;
}
.stars .rating{
height: 26px;
background: url(http://sandbox.bumbu.ru/ui/external/stars.png) 0 -26px repeat-x;
}
.stars input{
display: none;
}
.stars label{
display: none;
position: absolute;
top: 0;
left: 0;
height: 26px;
width: 130px;
cursor: pointer;
}
.stars:hover label{
display: block;
}
.stars label:hover{
background: url(http://sandbox.bumbu.ru/ui/external/stars.png) 0 -52px repeat-x;
}
.stars label + input + label{width: 104px;}
.stars label + input + label + input + label{width: 78px;}
.stars label + input + label + input + label + input + label{width: 52px;}
.stars label + input + label + input + label + input + label + input + label{width: 26px;}
.stars input:checked + label{
display: block;
background: url(http://sandbox.bumbu.ru/ui/external/stars.png) 0 -52px repeat-x;
}
Id's are unique in HTML. You can't have more than one element with the same id on the page and expect it to behave. This is exemplified by the behavior you are seeing. Since your label's have the for attribute set to the id's, the browser will check the input's for the first id it "sees", since it is only expecting one.
Each radio group also needs to have a unique name attribute, or all radios will be treated as a singe group and only one star will be able to be selected on the page.
So you need to change the id's for the second set of radios:
<div class="stars">
<div class="rating" style="width:65%"></div>
<input type="radio" name="rating" id="star5" value="5">
<label for="star5"></label>
<input type="radio" name="rating" id="star4" value="4">
<label for="star4"></label>
<input type="radio" name="rating" id="star3" value="3">
<label for="star3"></label>
<input type="radio" name="rating" id="star2" value="2">
<label for="star2"></label>
<input type="radio" name="rating" id="star1" value="1">
<label for="star1"></label>
</div>
</br>
<div class="stars">
<div class="rating" style="width:65%"></div>
<input type="radio" name="ratinga" id="star5a" value="5">
<label for="star5a"></label>
<input type="radio" name="ratinga" id="star4a" value="4">
<label for="star4a"></label>
<input type="radio" name="ratinga" id="star3a" value="3">
<label for="star3a"></label>
<input type="radio" name="ratinga" id="star2a" value="2">
<label for="star2a"></label>
<input type="radio" name="ratinga" id="star1a" value="1">
<label for="star1a"></label>
</div>

Make a horizontal radio button widget have fixed width

I have a horizontal radio button widget in my page that looks like this:
<form>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<input name="tool-selector" id="tool-selector-1" value="1" type="radio" checked>
<label for="tool-selector-1">1</label>
<input name="tool-selector" id="tool-selector-2" value="2" type="radio">
<label for="tool-selector-2">2</label>
<input name="tool-selector" id="tool-selector-3" value="3" type="radio">
<label for="tool-selector-3">3</label>
<input name="tool-selector" id="tool-selector-4" value="4" type="radio">
<label for="tool-selector-4">4</label>
<input name="tool-selector" id="tool-selector-5" value="5" type="radio">
<label for="tool-selector-5">5</label>
<input name="tool-selector" id="tool-selector-6" value="6" type="radio">
<label for="tool-selector-6">6</label>
<input name="tool-selector" id="tool-selector-7" value="7" type="radio">
<label for="tool-selector-7">7</label>
</fieldset>
</form>
I want it to always span the page width instead of not reaching to the end of the line if the screen is too wide or overflowing to the next line if it is too narrow. Is this possible, and if so, how can it be done?
Thanks.
Working example: http://jsfiddle.net/Gajotres/4KahY/
HTML:
<form>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<input name="tool-selector" id="tool-selector-1" value="1" type="radio" checked>
<label for="tool-selector-1">1</label>
<input name="tool-selector" id="tool-selector-2" value="2" type="radio">
<label for="tool-selector-2">2</label>
<input name="tool-selector" id="tool-selector-3" value="3" type="radio">
<label for="tool-selector-3">3</label>
<input name="tool-selector" id="tool-selector-4" value="4" type="radio">
<label for="tool-selector-4">4</label>
<input name="tool-selector" id="tool-selector-5" value="5" type="radio">
<label for="tool-selector-5">5</label>
<input name="tool-selector" id="tool-selector-6" value="6" type="radio">
<label for="tool-selector-6">6</label>
<input name="tool-selector" id="tool-selector-7" value="7" type="radio">
<label for="tool-selector-7">7</label>
</fieldset>
</form>
JavaScript:
.ui-controlgroup-controls {
width: 100% !important;
}
// This number shoud reflect 100 divided with number of controlgroup radio elements
.ui-controlgroup-controls .ui-radio {
width: 14.25% !important;
}
.ui-controlgroup-controls .ui-radio label {
text-align: center !important;
}

Only allow one radio button to be checked HTML

I have a series of radio buttons in which i'd only like 1 to be able to be selected. I have them all with the same name so I thought this would do the trick but i can still select all four.
<h1>Portion</h1>
<input type="radio" name="portion_num" value="2" /> Two
<input type="radio" name"portion_num" value="4" /> Four
<input type="radio" name"portion_num" value="6" /> Six
<input type="radio" name"portion_num" value="8" /> Eight
The reason it doesn't work is because your name attribute syntax is wrong.
name"portion_num" should be name="portion_num"
http://jsfiddle.net/65ba8/
Put them inside of form tags.
Like so
<form>
<input type="radio" name="portion_num" value="2" /> Two
<input type="radio" name="portion_num" value="4" /> Four
<input type="radio" name="portion_num" value="6" /> Six
<input type="radio" name="portion_num" value="8" /> Eight
</form>
http://jsfiddle.net/
<form>
<input type="radio" name="portion_num" value="2" />Two
<input type="radio" name="portion_num" value="4" />Four
<input type="radio" name="portion_num" value="6" />Six
<input type="radio" name="portion_num" value="8" />Eight
</form>