How to select label for checked checkbox using CSS? - css

I'm composing a stringbuilder on serverside (HTML code) and by ajax sending a response to jquery function that puts this HTML in place. On serverside is decided which checkbox will be checked. So far so good.
I would like to select labels for checked checkboxes and change colour so checked countries would be differently coloured. My trouble is that I can't select desired labels and change color property. I tried with this what you see and of course using classes and + and > and :before and other weird things...
So, how to select them and change any property on the label?
I would like to do it using CSS, I know how to do it using jquery but it seems so wrong.
label + input.chkCountry[type="checkbox"]:checked {color:green;}
<ul class="chkbox">
<li><label class="lblCountry" for="chkCC_AF"><input type="checkbox" class="chkCountry" id="chkCC_AF" name="chk_AF" value="AF" checked="checked">Afghanistan</label></li>
<li><label class="lblCountry" for="chkCC_AL"><input type="checkbox" class="chkCountry" id="chkCC_AL" name="chk_AL" value="AL">Albania</label></li>
<li><label class="lblCountry" for="chkCC_DZ"><input type="checkbox" class="chkCountry" id="chkCC_DZ" name="chk_DZ" value="DZ">Algeria</label></li>
<li><label class="lblCountry" for="chkCC_AS"><input type="checkbox" class="chkCountry" id="chkCC_AS" name="chk_AS" value="AS">American Samoa</label></li>
</ul>

You only need to change the HTML and selector. In CSS the label doesn't know if the checkbox is checked so you have to turn it around.
input.chkCountry[type="checkbox"]:checked + label {color:green;}
/*input:checked + label {color:green;} /* Short selector */
<ul class="chkbox">
<li>
<input type="checkbox" class="chkCountry" id="chkCC_AF" name="chk_AF" value="AF" checked="checked">
<label class="lblCountry" for="chkCC_AF">Afghanistan</label>
</li>
<li>
<input type="checkbox" class="chkCountry" id="chkCC_AL" name="chk_AL" value="AL">
<label class="lblCountry" for="chkCC_AL">Albania</label>
</li>
<li>
<input type="checkbox" class="chkCountry" id="chkCC_DZ" name="chk_DZ" value="DZ">
<label class="lblCountry" for="chkCC_DZ">Algeria</label>
</li>
<li><input type="checkbox" class="chkCountry" id="chkCC_AS" name="chk_AS" value="AS">
<label class="lblCountry" for="chkCC_AS">American Samoa</label>
</li>
</ul>

Follow below code example
input[type="checkbox"]:checked ~ label {
color: green;
}
<ul class="chkbox">
<li>
<input type="checkbox" id="chkCC_AF" name="chk_AF" value="AF" checked="checked">
<label class="lblCountry" for="chkCC_AF">Afghanistan</label>
</li>
<li>
<input type="checkbox" id="chkCC_AL" name="chk_AL" value="AL">
<label class="lblCountry" for="chkCC_AL">Albania</label>
</li>
</ul>
You will need to move label after checkbox in your HTML.

Try This way:
.chkCountry:checked + .lblCountry {
color: green;
}
<ul class="chkbox">
<li>
<input type="checkbox" class="chkCountry" id="chkCC_AF" name="chk_AF" value="AF" checked="checked">
<label class="lblCountry" for="chkCC_AF">Afghanistan</label>
</li>
<li>
<input type="checkbox" class="chkCountry" id="chkCC_AL" name="chk_AL" value="AL">
<label class="lblCountry" for="chkCC_AL">Albania</label></li>
<li>
<input type="checkbox" class="chkCountry" id="chkCC_DZ" name="chk_DZ" value="DZ">
<label class="lblCountry" for="chkCC_DZ">Algeria</label></li>
<li>
<input type="checkbox" class="chkCountry" id="chkCC_AS" name="chk_AS" value="AS">
<label class="lblCountry" for="chkCC_AS">AAmerican Samoa</label></li>
</ul>

Related

How to convert shipping methods to dropdown in Woocommerce

Hey in Woocommerce im trying to convert the shipping methods radio buttons to a dropdown list. this is the list html
<ul id="shipping_method">
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate1" value="flat_rate:1" class="shipping_method">
<label for="shipping_method_0_flat_rate1">רעננה: <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">₪</span>16</span></label> </li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate7" value="flat_rate:7" class="shipping_method" checked="checked">
<label for="shipping_method_0_flat_rate7">נתניה: <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">₪</span>30</span></label> </li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate8" value="flat_rate:8" class="shipping_method">
<label for="shipping_method_0_flat_rate8">חדרה: <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">₪</span>45</span></label> </li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_free_shipping3" value="free_shipping:3" class="shipping_method">
<label for="shipping_method_0_free_shipping3">איסוף עצמי חינם</label> </li>
</ul>
is there any hook i can use?
any quick trick ?
Try the WooCommerce Shipping Method Display Style plug-in (tested on WordPress v4.9.8 + WooCommerce v3.4.7):
https://wordpress.org/plugins/woo-shipping-display-mode/

PanelBar expands too far, then slides up

I have a panelbar which displays a few divs/ULs. The lists, when their width is set to 40%, for example, cause the panelbar to slide farther down than it should, and then jump back up to where it 'should' be. Remove the 40% on the UL, and everything works as expected.
Version 2015.3.930 has this issue, whereas older versions (randomly picked 2011.3.1407) do not.
<ul class="doctypecontainer noselect">
<li style="clear:both;">
<span>Truck Freight Bill (1)</span>
<div class="doctypecontainercontent">
<div class="docdatelabel"><input type="checkbox" />10/27/2015</div>
<ul class="pagelist">
<li><input type="checkbox" /><span>Page 1</span></li>
<li><input type="checkbox" /><span>Page 2</span></li>
<li><input type="checkbox" /><span>Page 3</span></li>
</ul>
<ul class="pagelist">
<li><input type="checkbox" /><span>Page 4</span></li>
<li><input type="checkbox" /><span>Page 5</span></li>
<li><input type="checkbox" /><span>Page 6</span></li>
</ul>
<div class="docdatelabel"><input type="checkbox" />11/15/2015</div>
<ul class="pagelist">
<li><input type="checkbox" /><span>Page 1</span></li>
<li><input type="checkbox" /><span>Page 2</span></li>
<li><input type="checkbox" /><span>Page 3</span></li>
</ul>
<div class="docdatelabel"><input type="checkbox" />11/21/2015</div>
<ul class="pagelist">
<li><input type="checkbox" /><span>Page 1</span></li>
<li><input type="checkbox" /><span>Page 2</span></li>
<li><input type="checkbox" /><span>Page 3</span></li>
</ul>
<span style="clear:left; display:block;"></span>
</div>
</li>
</ul>
See fiddle here: http://jsfiddle.net/u48kLrem/
remove the width:40% from the pagelist class, and it slides as expected.
I don't know, man. I suspect that it has to do with the text wrapping (or something wrapping) and causing it to miscalculate the height. Probably just bad coding on their part, but a simple modification causes the jump to disappear. Also, this modification should make it more reliable/future-proofed too.
.pagelist {
padding-bottom:5px;
list-style-type:none;
padding-left:10px;
width: 50%; /* change this to 50% */
float: left;
box-sizing: border-box; /* add this to force it to calculate
the padding in with the width to
total 50% */
}
Demo: http://jsfiddle.net/jmarikle/2ekxpuu6/

Checkbox labels wrapping

I can't seem to figure out how to stop the labels from wrapping here. Any thoughts?
<div>
<h4>Risk Category</h4>
<ul class="checkbox-grid">
<li><input type="checkbox" id="chkStrategic" value="Strategic" /><label>Strategic</label></li>
<li><input type="checkbox" id="chkEnvironmental" value="Environmental" /><label>Environmental</label></li>
<li><input type="checkbox" id="chkMarket" value="Market" /><label>Market</label></li>
<li><input type="checkbox" id="chkCredit" value="Credit" /><label>Credit</label></li>
<li><input type="checkbox" id="chkOperational" value="Operational" /><label>Operational</label></li>
<li><input type="checkbox" id="chkCompliance" value="Compliance" /><label>Compliance</label></li>
<li><input type="checkbox" id="chkBenefit" value="Benefit" /><label>Benefit</label></li>
<li><input type="checkbox" id="chkValue" value="Value" /><label>Value Delivery</label></li>
<li><input type="checkbox" id="chkProject" value="Project" /><label>Project Delivery</label></li>
<li><input type="checkbox" id="chkService" value="Service" /><label>Service Delivery</label></li>
<li><input type="checkbox" id="chkSecurity" value="Security" /><label>Security</label></li>
</ul>
</div>
Code Pen Showing the Problem
Thank you in advance.
JD
Set the display to inline instead of block. Block level elements tend to expand to their 100% width of the parent. inline or inline-block elements will align with their sibling elements.
#dialog-form label, input {
display: inline;
}
Updated Codepen
Simply add the following rules:
#dialog-form .checkbox-grid input,
#dialog-form .checkbox-grid label
{
display:inline;
}
The reason is that a previous rule set display:block to all label and input.
These new rules reset behaviour only for this kind of elements children of .checkbox-grid

Which part of this contact form I have to change if I am supposed to set up this form for my own website?

As an amateur who has never created/designed any kind of "form actions", I need help to use this form for a website I am currently designing. I feel okay with "CSS" and structure of the form itself. Just want to know which part of this contact form should be changed. Where to put my Email address?
<div class="segment contact-form">
<div class="center-wrap">
<div class='gf_browser_unknown gform_wrapper holla-form_wrapper' id='gform_wrapper_1'>
<form method='post' enctype='multipart/form-data' id='gform_1' class='holla-form' action='http://mammothmedia.tv/contact/'>
<div class='gform_body'>
<ul id='gform_fields_1' class='gform_fields top_label form_sublabel_below description_below'>
<li id='field_1_1' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_1'>First Name<span class='gfield_required'>*</span>
</label>
<div class='ginput_container'>
<input name='input_1' id='input_1_1' type='text' value='' class='medium' tabindex='1' />
</div>
</li>
<li id='field_1_8' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_8'>Last Name<span class='gfield_required'>*</span>
</label>
<div class='ginput_container'>
<input name='input_8' id='input_1_8' type='text' value='' class='medium' tabindex='2' />
</div>
</li>
<li id='field_1_2' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_2'>Email<span class='gfield_required'>*</span>
</label>
<div class='ginput_container'>
<input name='input_2' id='input_1_2' type='text' value='' class='medium' tabindex='3' />
</div>
</li>
<li id='field_1_3' class='gfield field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_3'>Phone</label>
<div class='ginput_container'>
<input name='input_3' id='input_1_3' type='text' value='' class='medium' tabindex='4' />
</div>
</li>
<li id='field_1_6' class='gfield field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_6'>Budget Range</label>
<div class='ginput_container'>
<input name='input_6' id='input_1_6' type='text' value='' class='medium' tabindex='5' />
</div>
</li>
<li id='field_1_5' class='gfield ginput_textarea field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_5'>Comments</label>
<div class='ginput_container'>
<textarea name='input_5' id='input_1_5' class='textarea medium' tabindex='6' rows='10' cols='50'></textarea>
</div>
</li>
<li id='field_1_7' class='gfield ginput_subscribe field_sublabel_below field_description_below'>
<label class='gfield_label'></label>
<div class='ginput_container'>
<ul class='gfield_checkbox' id='input_1_7'>
<li class='gchoice_1_7_1'>
<input name='input_7.1' type='checkbox' value='Subscribe to our newsletter' id='choice_1_7_1' tabindex='7' />
<label for='choice_1_7_1' id='label_1_7_1'>Subscribe to our newsletter</label>
</li>
</ul>
</div>
</li>
<li id='field_1_9' class='gfield gform_validation_container field_sublabel_below field_description_below'>
<label class='gfield_label' for='input_1_9'>Comments</label>
<div class='ginput_container'>
<input name='input_9' id='input_1_9' type='text' value='' />
</div>
<div class='gfield_description'>This field is for validation purposes and should be left unchanged.</div>
</li>
</ul>
</div>
<div class='gform_footer top_label'>
<input type='submit' id='gform_submit_button_1' class='gform_button button' value='Submit' tabindex='8' onclick='if(window["gf_submitting_1"]){return false;} window["gf_submitting_1"]=true; ' />
<input type='hidden' class='gform_hidden' name='is_submit_1' value='1' />
<input type='hidden' class='gform_hidden' name='gform_submit' value='1' />
<input type='hidden' class='gform_hidden' name='gform_unique_id' value='' />
<input type='hidden' class='gform_hidden' name='state_1' value='WyJbXSIsIjA0OGE5MTQyNDdhM2NhZjFiMTc5Nzk5ZjM1ZTIzZjYzIl0=' />
<input type='hidden' class='gform_hidden' name='gform_target_page_number_1' id='gform_target_page_number_1' value='0' />
<input type='hidden' class='gform_hidden' name='gform_source_page_number_1' id='gform_source_page_number_1' value='1' />
<input type='hidden' name='gform_field_values' value='' />
</div>
</form>
</div>
<script type='text/javascript'>
jQuery(document).bind('gform_post_render', function(event, formId, currentPage) {
if (formId == 1) {
jQuery('#input_1_3').mask('(999) 999-9999').bind('keypress', function(e) {
if (e.which == 13) {
jQuery(this).blur();
}
});
}
});
jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit) {});
</script>
<script type='text/javascript'>
jQuery(document).ready(function({
jQuery(document).trigger('gform_post_render', [1, 1])
});
</script>
</div>
</div>
You will not be able to use this because this form uses a WordPress Plugin called Gravity Form's
Also most form's use PHP and you wont be able to grab PHP from client side.
Which server side language are you using? PHP, ASP.NET, etc? If you're trying to make a form that will send an email to an email address you'll have to set up some server side code. Right now it looks like it sends the form data to http://mammothmedia.tv/contact/ but configuring smtp for emailing is going to depend on the server side language you're using. On another note, your site looks really nice ;)
EDIT:
Check out: http://www.freecontactform.com/email_form.php , that oughta get you started.

What tag should be used to make Form layout if we can't use only pure semantic way?

i know it is pure semantic way
<form action="" method="">
<fieldset>
<legend>Contact Form</legend>
<label for="name">Name</label>
<input name="name" id="name" size="20" />
</fieldset>
<form>
But some time for some design purpose it's not sufficient to get needed style. so my question is other than this purely semantic method
isn't this code is also semantic (after pure semantic method) because form is a group of ordered fields which we fill one by one
ol {
list-style: none;
padding-left: 0;
}
<form action="" method="">
<fieldset>
<legend>Contact Form</legend>
<ol>
<li>
<label for="name">Name</label>
<input name="name" id="name" size="20" />
</li>
<li>
<label for="email">Email</label>
<input name="email" id="email" size="20" />
</li>
<li>
<label for=" Choices"> Choices (radio)</label>
<input type="radio" name=" Choice" /> Choice 1
<input type="radio" name=" Choice" /> Choice 2
<input type="radio" name=" Choice" /> Choice 3
</li>
<li>
<label for=" Choices3"> Choices (checkbox)</label>
<input type="checkbox" name=" Choice3" /> Choice 1
<input type="checkbox" name=" Choice3" /> Choice 2
<input type="checkbox" name=" Choice3" /> Choice 3
</li>
<li>
<label for="dropdown">Question</label>
<select id="dropdown">
<optgroup label="Group of Options">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</optgroup>
</select>
</li>
<li>
<label for="message">Message</label><br />
<textarea name="message"rows="12" cols="36"></textarea>
</li>
<li><input type="submit" value="send it" /></li>
</ol>
</fieldset>
</form>
If the form fields are meant to be completed in a particular order, then yes, I would say an ordered list is semantically meaningful for separating form elements.
If you want to add extra elements to allow more layout styling hooks from CSS, but which have no semantic content in themselves, use <div> (or <span> for inline). That's what they're there for.
You should use a definition list, that way your label / input are linked to one another through the for and id, but also through the definition title (label) and definition description (input).
That way you can do some good styling or hide some stuff if needed.

Resources