This HTML code shows two checkboxes next to each other
<div id="mr_mrs">
<ul class="mr_mrs form-no-clear">
<li id="mr" class="popular-category">
<label for="Mr" id="mr">Mr</label>
<span><input name="Mr" id="Mr" type="checkbox" /></span>
<div class="clearboth"></div>
</li>
<li id="mrs" class="popular-category">
<label for="Mrs" id="mrs">Mrs</label>
<span><input name="Mrs" id="Mrs" type="checkbox" /></span>
<div class="clearboth"></div>
</li>
</ul>
</div>
I want to customize the checkboxed to square and on selecting the checkbox fill some color to it. IMAGE BELOW
How can this be done ?
To sit the two controls next to each other, set their display to inline block: display: inline-block. (Default for div is block display.)
To enable the user to check the box by clicking the label text, there are a couple options. Both are shown in the example below.
<label> is parent to the text and checkbox.
Use <label for="myId">some text</label><input id="myId"> to associate the label to the input.*
*Note: when using the for/id method, it's label-for and input-id. I noticed in the example the id was applied to both elements, an id should be unique to the page.
.checkbox {
margin: 4px;
display: inline-block;
}
<div class="checkbox">
<label>Box 1<input type="checkbox"></label>
</div>
<div class="checkbox">
<label for="myId">Box 2</label>
<input id="myId" type="checkbox">
</div>
Related
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 an issue. I am trying to create a single line that contains a radio, a label, and a clickable icon and I want all of these elements to be inline. I want it to be set up like:
Radio Label Icon
in that order. My code HTML looks like this:
<div class="wrapper class>
<div class="radio" label="this is my label">
<input type="radio" value="1" required>
<i class="material-icons" ng-click="some-action">info_outline</i>
</div>
</div>
I have tried to place the icon outside of the label class, but it does not display inline and I have also tried to use display:inline; in my CSS code, to no avail. I am trying to just separate the icon and the label, but I cannot seem to get this to work.
Any and all help would be greatly appreciated!
Thank you in advance!
Change the div class="radio" to an span:
<div class="wrapper">
<span class="radio" label="this is my label">
<input type="radio" value="1" required>
<i class="material-icons" ng-click="some-action">info_outline</i>
</span>
</div>
https://jsfiddle.net/qq3nLwp3/
And improved with some css:
div.wrapper input, div.wrapper i { {
vertical-align: middle;
}
In Bootstrap, how do I get checkboxes to align with other text on the same line? The checkboxes are always hanging lower than a line of text. I tried wrapping the separate text in a div and adding padding but it does nothing.
<div class="col-xs-12 move-down">
<div style="padding-top:7px; display:inline-block;">This is a new email address. Would you like to:</div>
<div style="display:inline-block;">
<label class="checkbox-inline" data-toggle="collapse" href="#collapsesignup">
<input type="checkbox" id="" value="option1"> Create account
</label> <label class="checkbox-inline">
<input type="checkbox" id="" value="option1"> Guest checkout
</label>
</div>
</div>
Looks fine when I copy your code into a jsfiddle
But, in situation like this, a position: relative would be helpful
https://jsfiddle.net/jacobgoh101/wne16hm1/
.checkbox-wrapper {
position: relative;
top: -1px;
}
Using Bootstrap version 2.3.2, I have a form layout like the below image and since the checkbox has an inline label, there is an aligning issue.
Adding margin to input[type="checkbox"] only gives margin to the checkbox, not the inline label. How do I make it so the checkbox and its label vertically align to the text fields next to it?
Here is the
JS BIN if you are interested.
In your HTML add a class that will handle the checkbox margin:
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<label>label 1</label>
<input type="text" />
</div>
<div class="span3">
<label>label 2</label>
<input type="text" />
</div>
<div class="span3 checkbox">
<input type="checkbox" />test description
</div>
</div>
</div>
and in your CSS:
input[type="checkbox"] {
// i just remove this part..
}
.checkbox {
margin: 30px 0 0 0;
}
Don't put the margin on the checkbox, but on the parent div.
Check this jsFiddle.
Hope this helps
Try to always use something like this:
<div class="span3">
<label for="checkbox" class="checkbox">
<input type="checkbox" id="checkbox" class="checkbox">test description
</label>
</div>
http://jsbin.com/itAdAWA/1/edit
How about putting a <label> before the checkbox like this? ..
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<label>label 1</label>
<input type="text">
</div>
<div class="span3">
<label>label 2</label>
<input type="text">
</div>
<div class="span3">
<label>test</label>
<input type="checkbox">
</div>
</div>
</div>
Bootply: http://bootply.com/86998
I just solved this exact problem in bootstrap 3, by simply limiting the height of inline checkboxes to 12 pixels. They are by default 40px, I don't know why !
<div class="checkbox-inline">
<label>
<input type="checkbox" checked="checked" />
<span>My correctly aligned check-box</span>
</label>
</div>
add this in your css file (I personally have a css file named bootstrap-custom.css):
/*
Checkboxes in inline forms are misaligned because for an unknow reason they inherit a height of 40px !
This selector limit the height of inline checkboxes to 12px which is the perfect value to align them to
the other widgets in an inline form.
*/
.radio-inline, .checkbox-inline {
max-height: 12px;
}
Not ideal solution but change your code to ...
<div class="span5">
<input type="checkbox">test description</input>
</div>
and set the margin-top on that. I will result as you want - better.
Bootstrap v5+
<!-- mt-md-4 pt-md-3 this apply margin and padding only for desktop -->
<div class="col-md-3 mb-3 md-mt-4 md-pt-3">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
I have tried everything to align these boxes, so they start from the same place downwards.
I'm not sure which div to put in my stylesheet
<div class="boxes">
<p class="h3"> You are able to add up to 3 addresses.
Please select the type of address, using the following guide
<ul>
<li>H: Permanent home address</li>
<li>P: Postal address (where you will be from June to September)</li>
<li>L: Local address (where you currently live)</li>
</ul>
</p>
<div id="address">
<div id="input1" style="margin-bottom:4px;" class="input">
Street<span class="required">*</span>
<input name="Street[]" type="text" >
</div>
<div id="input2" style="margin-bottom:4px;" class="input">
Line2
<input name="Line2[]" type="text" >
</div>
<div id="input3" style="margin-bottom:4px;" class="input">
Line3
<input name="Line3[]" type="text" >
</div>
Any ideas?
Having amended your HTML, to wrap the label/associated text in actual label elements, added a for attribute to those elements and a corresponding id attribute to the input elements:
<div class="boxes">
<p class="h3">
You are able to add up to 3 addresses. Please select the type of address, using the following guide
<ul>
<li>H: Permanent home address</li>
<li>P: Postal address (where you will be from June to September)</li>
<li>L: Local address (where you currently live)</li>
</ul>
</p>
<div id="address">
<div id="input1" style="margin-bottom:4px;" class="input">
<label for="street">Street<span class="required">*</span></label><input name="Street[]" id="street" type="text">
</div>
<div id="input2" style="margin-bottom:4px;" class="input">
<label for="line2">Line2</label><input id="line2" name="Line2[]" type="text">
</div>
<div id="input3" style="margin-bottom:4px;" class="input">
<label for="line3">Line3</label><input id="line3" name="Line3[]" type="text">
</div>
</div>
</div>
The following CSS works:
#address label {
display: inline-block;
width: 5em;
text-align: right;
padding-right: 0.5em;
}
#address input {
display: inline-block;
}
JS Fiddle demo.
In the above, once the text was wrapped in a tag (to become the label element), it could then be assigned display: inline-block; and could then be given a width. Also, white-space was removed from between the close of the label and the opening of the input, in order to prevent white-space in the HTML file causing any space between the two elements.