I am a beginner, and I'm building a simple calculator in which there are several options that can be included in the total result. Upon checking a checkbox "front bumper" it will reveal three different options for that front bumper. This is not working the same with all options.
Once the CSS worked for the front bumper checkbox, I copied and pasted for the back bumper and the door handles...but only the front bumper and door handles is actually working, while the back bumper doesn't reveal any of the additional options when checked. The code for all three is identical (save the class names) so I'm not sure why they aren't working the same.
Like I said, I'm a beginner, so please excuse my messy code.
Just for context, the app is to calculate vehicle wrap pricing based on the options, it's my day job so easier to build apps for something I know a ton about already.
<div class="options">
<p>Options</p>
<div class="flexbox-one-a">
<div class="bumpers">
<div class="front-bumper">
<input type="checkbox"id="front-bumper"> <label for="front-bumper">Front Bumper</label>
<div class="reveal-if-active-front">
<input type="radio" name="front-bumper" class="front-standard"><label for="front-standard">Standard</label><br>
<input type="radio" name="front-bumper" class="front-complex"><label for="front-complex">Complex</label><br>
<input type="radio" name="front-bumper" class="front-highlycomplex"><label for="front-highlycomplex">Highly Complex</label>
</div>
</div>
<div class="back-bumper">
<input type="checkbox"id="back-bumper"> <label for="back-bumper">Back Bumper<label>
<div class="reveal-if-active-back">
<input type="radio" name="back-bumper" class="back-standard"><label for="back-standard">Standard</label><br>
<input type="radio" name="back-bumper" class="back-complex"><label for="back-complex">Complex</label><br>
<input type="radio" name="back-bumper" class="back-highlycomplex"><label for="back-highlycomplex">Highly Complex</label>
</div>
</div>
</div>
<div class="mirrors-and-handles">
<div class="mirrors">
<input type="checkbox" id="mirrors"><label for="mirrors">Mirrors</label>
</div>
<div class="door-handles">
<input type="checkbox"id="door-handles"> <label for="door-handles">Door Handles</label>
<div class="reveal-if-active-handles">
<input type="radio" name="door-handles" class="two-handles"><label for="two-handles">2 Handles</label><br>
<input type="radio" name="door-handles" class="four-handles"><label for="four-handles">4 Handles</label><br>
</div>
</div>
</div>
</div>
</div>
.reveal-if-active-front, .reveal-if-active-back, .reveal-if-active-handles {
opacity: 0;
max-height: 0;
overflow: hidden;
}
.options input[type="checkbox"]:checked ~ .reveal-if-active-front {
opacity: 1;
max-height: 100px;
overflow: visible;
}
.options input[type="checkbox"]:checked ~ .reveal-if-active-back {
opacity: 1;
max-height: 100px;
overflow: visible;
}
.options input[type="checkbox"]:checked ~ .reveal-if-active-handles {
opacity: 1;
max-height: 100px;
overflow: visible;
}
You forgot to close back-bumper <label> tag.
<label for="back-bumper">Back Bumper</label>
This is a common problem for beginners.
You can use these online tools to check your HTML code and find out related issues:
HTML Validator / Linter
Closing Tag Checker for HTML5 by Alicia Ramirez
Related
I have this working for a checkbox. When I select the checkbox, my two radio buttons appear. But now, if I select one of the radio buttons, I want a block of address fields to appear. I'm not sure why the same thing that is working for the checkbox isn't working for the radio button.
<form>
<input class="no22XAddressRadioButtons_activator" type="checkbox">
Check if you do not have a physical address within the Oakland Beat 22X boundary.
<div class="no22XAddressRadioButtons">
<input class="outsideAddress_activator" type="radio" name="no22XAddress" id="outsideAddress_activator">
<label for="outsideAddress_activator">My physical address is outside of the 22X boundary.</label><br>
<input class="noAddress" type="radio" name="no22XAddress" id="no22XAddress">
<label for="no22XAddress">I don't have a physical address.</label><br>
</div>
<!--Begin conditional address-->
<div class="outsideAddressTextFields">
Enter your physical address including city, state, and zip code.
<input class="outsideAddress" type="text">
<label class="labelText" for="outsideAddress">Number and Street</label>
<input type="text" name="outsideAddress" id="outsideAddress" required>
</div>
</form>
/* Begin conditional radio buttons */
.no22XAddressRadioButtons {
display: none;
}
.no22XAddressRadioButtons_activator {
margin-left: 30px;
}
.no22XAddressRadioButtons_activator:checked + .no22XAddressRadioButtons {
display: block;
margin-left: 45px;
}
/* Begin conditional address */
.outsideAddressTextFields{
display: none;
}
.outsideAddress_activator:checked + .outsideAddressTextFields {
display: block;
}
Thats because you're using +, an Adjacent sibling combinator. Which means the block that you need to be made visible, while an input is checked has to be right after the said input. You can use a General sibling combinator which I think might be helpful in you case. I've attached a modified code snippet to demonstrate.
As a side note: use labels to associate an input to a caption.
You can click the associated label to focus/activate the input, as well as the input itself. This increased hit area provides an advantage to anyone trying to activate the input, including those using a touch-screen device.
/* Begin conditional radio buttons */
.no22XAddressRadioButtons {
display: none;
}
.no22XAddressRadioButtons_activator {
margin-left: 30px;
}
.no22XAddressRadioButtons_activator:checked ~ .no22XAddressRadioButtons {
display: block;
margin-left: 45px;
}
/* Begin conditional address */
.outsideAddressTextFields{
display: none;
}
.outsideAddress_activator:checked ~ .outsideAddressTextFields {
display: block;
}
<form>
<input id="addressCheck" class="no22XAddressRadioButtons_activator" type="checkbox">
<label for="addressCheck">Check if you do not have a physical address within the Oakland Beat 22X boundary.</label>
<div class="no22XAddressRadioButtons">
<div>
<input class="outsideAddress_activator" type="radio" name="no22XAddress" id="outsideAddress_activator">
<label for="outsideAddress_activator">My physical address is outside of the 22X boundary.</label>
<!--Begin conditional address-->
<div class="outsideAddressTextFields">
<div>
<label for="insideAddress">Enter your physical address including city, state, and zip code.</label>
<input class="outsideAddress" type="text" id="insideAddress">
</div>
<div>
<label class="labelText" for="outsideAddress">Number and Street</label>
<input type="text" name="outsideAddress" id="outsideAddress" required>
</div>
</div>
</div>
<div>
<input class="noAddress" type="radio" name="no22XAddress" id="no22XAddress">
<label for="no22XAddress">I don't have a physical address.</label><br>
</div>
</div>
</form>
I have an un-editable HTML, which cannot change anything.
I need to hide the first checkbox and the second one will show. It is done in CSS, but somehow it doesn't work as expected.
Here is its LIVE sample.
Please help.
.treeview-container .treeview-item:first-child .form-check label input[type="checkbox"] {
visibility: hidden;
}
<div class="treeview-container">
<div class="treeview-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" />First Box
</label>
</div>
<div class="treeview-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" />Second Box
</label>
</div>
</div>
</div>
</div>
The problem is that .treeview-item:first-child is targetting both of the checkboxes' respective .form-check containers (as they are both the first child of their parent .treeview-item).
This is perhaps a little counter-intuitive, as you may expect the :first-child pseudo-selector to only target the very first occurence of a child of .treeview-item. This is not the case, as the :first-child selector actually targets the first child of each of the .treeview-item parents.
In order to correct this, you can simply use two child combinator selectors (>) to ensure that .treeview-item is a direct child of .treeview-container, and .form-check is a direct child of that .treeview-item.
This can be seen in the following:
.treeview-container > .treeview-item > .form-check label input[type="checkbox"] {
visibility: hidden;
}
<div class="treeview-container">
<div class="treeview-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" />First Box
</label>
</div>
<div class="treeview-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" />Second Box
</label>
</div>
</div>
</div>
</div>
Hope this helps! :)
.treeview-item:first-of-type {
display: none;
}
You can create an ID and add it to any elements you want hidden. However this only hides the element. If you do not want the user to be able to change the checkbox you may want to remove that input type all together.
.treeview-container .treeview-item:first-child .form-check label input[type="checkbox"] {
visibility: hidden;
}
#hideMe {
display: none;
}
<div class="treeview-container">
<div class="treeview-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" id = "hideMe"/>First Box
</label>
</div>
<div class="treeview-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" />Second Box
</label>
</div>
</div>
</div>
</div>
Using child combinator (>) in between two selectors will select a direct child of the parent. Currently, your code is selecting both inputs as you are just checking for decendents ..ie if the input has an ancestor as .treeview-container or not.
So using two consecutive child combinator will help you get expected result.
Code below.
.treeview-container > div > .form-check label input[type="checkbox"] {
visibility: hidden;
}
I have encountered a problem where I tried to click between black lines and it doesn't triggered anything, but triggers when clicked on the black lines. I added div so that I can add cursor pointer around the area. I am aware that it must be something with the for=nav-trigger located in the html, however "for" doesn't work with div. Is there a workaround?
<div id="menu">
<input type="checkbox" id="nav-trigger" class="nav-trigger"/>
<label id="menuButton" for="nav-trigger"></label>
</div>
Here is the link to jsfiddle: https://jsfiddle.net/dxs6040/51wdfypj/14/
Use the html like this:
<div id="menu">
<label for="nav-trigger">
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<span id="menuButton"></span>
</label>
</div>
and add this to css:
label {
position: absolute;
height: 100%;
width: 100%;
cursor: pointer;
}
jsfiddle:
https://jsfiddle.net/e9qafkbr/
I'm using the following mark up and styles (Bootstrap). It shows my checkbox but it is paralysed, that is, it cannot be checked. here is my mark up:
I want something more Bootstrap-ish. I know there are other options to make the checkbox look fancy but that do not solve the problem.
<div class="form-group">
<div class="checkbox">
1.
<input type="checkbox" name="options" id="chk2" />
<label class="checkbox-label">Option 2</label>
</div>
</div>
Here is how it looks.
What exactly is the issue?
If I put the input element inside label I get this ugly thing:
<input type="checkbox" name="options" id="chk2" />
<label class="checkbox-label">Option 2</label>
The problem is with your label. The for attribute must match with the name attribute of your label
Looks need to tweak bootstrap styling for custom checkbox.
Check this
HTML
<div class="form-group">
<div class="checkbox">
<label for="check">
<input type="checkbox" id="check"/>
<span class="fake-input"></span>
<span class="fake-label">Option 2</span>
</label>
</div>
</div
CSS
.fake-input {
float: left;
width: 20px;
height: 20px;
border: 1px solid #9f9f9f;
background: #fff;
vertical-align: middle;
position: relative;
margin-right: 10px;
border-radius: 4px;
}
input[type="checkbox"] {
position: fixed;
top: -9999px;
left: -9999px;
}
input[type="checkbox"]:checked + .fake-input:before {
content:"\2713";
position: absolute;
color: #000;
text-align: center;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
Check in Fiddle
Reading around it looks like you have to style the checked version and the unchecked version.
input[type=checkbox]:checked {
}
Styling with this tag should solve your problems.
Use "for" attribute to solve this issue.
<div class="form-group">
<div class="checkbox">
1.
<input type="checkbox" name="options" id="chk2" />
<label for="chk2" class="checkbox-label">Option 2</label>
</div>
</div>
<div class="col-md-3">
<input class="form-check-input" type="checkbox" id="" asp-for="">
<label class="form-check-label" for="" asp-for="">
</label>
</div>
It's not due to Bootstrap but to Wordpress. The checkboxes became visible after I added "display:block;" to the css of the checkbox input tag.
<input class="form-check-input" type="checkbox" id="">
input.form-check-input {
display:block;
}
I'm trying to make a color picker by setting up html like this:
<ol class="kleurenkiezer list-reset clearfix">
<li>
<input type="radio" id="kleur_wit" name="kleurenkiezer" value="wit">
<label for="kleur_wit" style="background: white;"></label>
</li>
<li>
<input type="radio" id="kleur_creme" name="kleurenkiezer" value="creme">
<label for="kleur_creme" style="background: #fffceb;"></label>
</li>
<li>
<input type="radio" id="kleur_lichtbruin" name="kleurenkiezer" value="lichtbruin">
<label for="kleur_lichtbruin" style="background: #968272;"></label>
</li>
<li>
<input type="radio" id="kleur_bordeauxrood" name="kleurenkiezer" value="bordeauxrood">
<label for="kleur_bordeauxrood" style="background: #941514;"></label>
</li>
<li>
<input type="radio" id="kleur_oudgroen" name="kleurenkiezer" value="oudgroen">
<label for="kleur_oudgroen" style="background: #7fa298;"></label>
</li>
<li>
<input type="radio" id="kleur_lichtblauw" name="kleurenkiezer" value="lichtblauw">
<label for="kleur_lichtblauw" style="background: #487eae;"></label>
</li>
<li>
<input type="radio" id="kleur_oudgeel" name="kleurenkiezer" value="oudgeel">
<label for="kleur_oudgeel" style="background: #b79130;"></label>
</li>
<li>
<input type="radio" id="kleur_zwart" name="kleurenkiezer" value="zwart">
<label for="kleur_zwart" style="background: #000;"></label>
</li>
</ol>
What I'm trying to do is make the actual radio button invisible to the user and make the label clickable so that I have a neat list of colored squares that you can select one of. Now my radio button doesn't seem to get checked.. Why would that be?
My css:
.kleurenkiezer {
width: 165px;
margin-left: -10px;
float: right;
}
.kleurenkiezer li {
position: relative;
width: 45px;
height: 45px;
margin: 0 0 10px 10px;
border: 1px solid #bbbbbb;
float: left;
}
.kleurenkiezer li input {
position: absolute;
top: 10px;
left: 10px;
z-index: 1000;
}
.kleurenkiezer li label {
position: absolute;
top: 0;
left: 0;
width: 43px;
height: 43px;
}
New answer for really old question.. :) Not sure it's your case, but I'm experimentind the same exact issue when clicking labels on a page where there are 2 duplicated forms, one of the 2 always hidden. One is used on a page area for mobile devices, the other for desktop devices.
The one appearing first on html flow is working properly, the other no. Fake example, see js fiddle:
<input type="radio" id="value-1" name="sort"/>
<label for="value-1">value 1</label>
<input type="radio" id="value-2" name="sort"/>
<label for="value-2">value 2</label>
<input type="radio" id="value-1" name="sort"/>
<label for="value-1">value 1</label>
<input type="radio" id="value-2" name="sort"/>
<label for="value-2">value 2</label>
https://jsfiddle.net/stratboy/8ua16gm3/1/
So for now, for me, the trick here is to find a way to avoid form duplication.
The radio button work for me.
You can set in css display:none for input checkbox:
.kleurenkiezer input[type=radio] {
display:none
}
For the same thing (a colorpicker) i used another approach and i think it's simpler. Just replace your form with a list of buttons and build 1 function where you pass the color. it's something like this:
<li class="color-box"><button type="button" class="color-btn" style="background-color:#BDC3C7;" onclick="wFontColour('#BDC3C7')"></button></li>
then in your function you do whatever you need to with that colour, in my case it looked like this:
function wFontColour(fontColour) {
document.execCommand("foreColor", false, fontColour);
};
if you want to keep your approach, give your label an id and try this:
$('#myLabel').each('click', function(){
$(this).closest('input:radio').attr('checked', 'checked');
});
Setting an attribute checked won't allow to re checked when you clicked once again. it will work for only once. Give following code a try
$(document).on('click','li label', function(){
$(this).closest('li').find('input:radio').trigger('click');
});
I experienced the same problem as #Luca (and possibly OP) using simple_form_for() in a mobile view and a desktop view. The mobile and desktop inputs had duplicate ids that were causing issues. I ended up using :namespace in the mobile view form:
<%= simple_form_for(:registration, namespace: "mobile") do |f| %>
The namespace generated ids that were unique and my radio buttons worked correctly after that.