Is it posible to make an input checkbox a Bootstrap glyphicon? - css

Is it posible to make an input checkbox a Bootstrap glyphicon?
I want to make up the default checkboxes with a nice Bootstrap glyphicon.
For example: glyphicon glyphicon-unchecked and when checked: glyphicon glyphicon-check.
I've tried this:
input[type='checkbox'] {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: 400;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
content: "\e157";
}
But nothing happened..
I don't know if that's posible?

You can achieve that in a couple of methods:
Method 1
inside a <label> tag, two <tags> that represent the icons that you want need to be placed(or outside, per use scenario)
then toggle these two <tags>, when the input[type='checkbox'] is checked or unchecked
done.
Method 2
a cleaner approach to the above one, would be to use the css from bootstraps icons, and place them in a :before(or :after depending on your scenarion) on the <label> tag
then toggle the content prop. of the :before class, that the icons that you want have, when the input[type='checkbox'] is checked or unchecked
done.
Check out the demo here and also, a couple of more through documentation on this matter:
Add boostrap icon to input boxes
Boostrap checkbox documentation

If you're able to modify your markup a bit, this should do:
<label for="myCheckbox" class="glyphy">
<input type="checkbox" id="myCheckbox" />
<span class="glyphicon glyphicon-unchecked"></span>
label words
</label>
$('.glyphy').click(function (e) {
if ($(e.target).is('input')) { // prevent double-event due to bubbling
$(this).find('.glyphicon').toggleClass('glyphicon-check glyphicon-unchecked');
}
});
Demo

if you have the icons, you can style it as such: http://jsfiddle.net/swm53ran/164/
/*hide checkbox and radio buttons*/
input[type=checkbox],
input[type=radio] {
width: 2em;
margin: 0;
padding: 0;
font-size: 1em;
opacity: 0; /*This is the part tht actually hides it*/
}
/*normalize the spacing*/
input[type=checkbox] + label,
input[type=radio] + label {
display: inline-block;
margin-left: -2em;
line-height: 1.5em;
}
/*unchecked css*/
input[type=checkbox] + label > span,
input[type=radio] + label > span {
display: inline-block;
background-image: url('http://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Face-sad.svg/48px-Face-sad.svg.png');
width: 50px;
height: 50px;
}
/*selected checkbox css*/
input[type=checkbox]:checked + label > span > span {
width: 50px;
height: 50px;
display:block;
background-image: url('http://wscont1.apps.microsoft.com/winstore/1x/a14c3995-34d7-454c-82e2-0c192e48b91a/Icon.173718.png');
}
/*selected radio css*/
input[type=radio]:checked + label > span > span {
width: 50px;
height: 50px;
display:block;
background-image: url('http://wscont1.apps.microsoft.com/winstore/1x/a14c3995-34d7-454c-82e2-0c192e48b91a/Icon.173718.png');
}
<div>
<input id="check1" type="checkbox" name="check1" value="check1" />
<label for="check1"><span><span></span></span>Checkbox</label>
</div>
<div>
<input id="radio1" type="radio" name="radio" value="radio1" />
<label for="radio1"><span><span></span></span>Radio1</label>
</div>
<div>
<input id="radio2" type="radio" name="radio" value="radio2" />
<label for="radio2"><span><span></span></span>Radio2</label>
</div>

Related

In CSS, selecting parent <label> for an <input> that is selected

Edit: apparently cant use <> braces or it hides names?...
I've seen a few variations of this question asked, however none of what I found fits my particular issue, which I think is a simple issue. I am creating the following radio button group in react:
const myOptions = ["YTD", "Week", "Month", "Pre AS", "Post AS"]
const myButtons =
<form>
<div className="radio-group">
{myOptions.map((d, i) => {
return (
<label>
<input
type={"radio"}
value={myOptions[i]}
checked={timeframeNew === myOptions[i]}
onChange={this.handleTimeframeNewChange}
/>
<span>{myOptions[i]}</span>
</label>
)
})}
</div>
</form>;
and here is my current CSS for styling the buttons to look nice...
input[type=radio] {
position: absolute;
visibility: hidden;
display: none;
}
label {
color: #333;
background: #EEE;
display: inline-block;
cursor: pointer;
font-weight: bold;
padding: 5px 20px;
border: 2px solid orange;
}
input[type=radio]:checked + label {
color: red;
background: #333;
}
label + input[type=radio] + label {
border-left: solid 2px blue;
}
.radio-group {
border: solid 2px green;
display: inline-block;
margin: 20px;
border-radius: 10px;
overflow: hidden;
}
Unfortunately, the CSS is not working as intended. In particular, the following selection - input[type=radio]:checked + label does not work because there is no label immediately after an input. The only way so far I have been able to successfully get my react onChange handler function to work is by putting the input inside of the label, like this, and then returning the label in each .map loop.
*Since the return needs to be a single element, if I want to take the out of the label, I would need to then include them both in a div or a span, and for some reason doing so breaks my onChange handler...
So my question is, how how how can I, in CSS, grab the label that corresponds to the clicked input. I would like to change the entire label's color and background when it is / isn't clicked, so selecting the span does not help (since that only changes the texts color/background, not the whole label.
Thanks in advance!!
CSS can select child and sibling elements, but not parent elements. I often hide default radio buttons and checkboxes and create my own, like this:
.button-group{
font-size:0; /*Prevents a space from occuring between buttons*/
}
.button-group input{
position:absolute;
visibility:hidden; /* display:none causes some browsers to ignore the input altogether */
}
.button-group input+span{
display:inline-block;
line-height:20px;
font-size:1rem;
vertical-align:top;
padding:0 10px;
color:#000;
border-left:1px solid #a00;
}
.button-group label:first-child input+span{
border-radius:10px 0 0 10px;
border-left:0;
}
.button-group label:last-child input+span{
border-radius:0 10px 10px 0;
}
.button-group input:not(:checked)+span{
background-color:#faa;
}
.button-group input:not(:checked)+span:hover{
background-color:#f66;
}
input[type=radio]:checked+span{
background-color:#f33;
}
<div class="button-group">
<label>
<input type="radio" value="1" name="myfield" />
<span>Option 1</span>
</label>
<label>
<input type="radio" value="2" name="myfield" />
<span>Option 2</span>
</label>
<label>
<input type="radio" value="3" name="myfield" />
<span>Option 3</span>
</label>
</div>
*Since the return needs to be a single element, if I want to take the out of the label, I would need to then include them both in a div or a span, and for some reason doing so breaks my onChange handler...
You can use <React.Fragment> <input /> <span /> </ReactFragment> to return multiple elements without rendering them inside a div or span

Custom CSS to radio button labels

I need to add custom styling to the checked/active radio button behind the label.
I can get the border and width of the buttons fine, just can't set a background color to the checked/active button only. As the input-label is outside the div I can't seem to manage it.
I can't mess with the code below, can only change CSS.
Can anyone help me please?
<label class="radio-inline display-block col-sm-3" for="concern" style="color: rgb(102, 102, 102);">
<span class="has-pretty-child">
<div class="clearfix prettyradio labelright blue has-pretty-child">
<input class="radio the_input_element" name="runway_surface" id="concern" value="Concern" style="display: block !important; color: rgb(50, 55, 60);" autocomplete="off" type="radio">
<a class="checked fa fa-check ui-state-active" style="color: rgb(0, 163, 201);"></a>
</div>
<span class="input-label radio-label" style="color: rgb(102, 102, 102);">Concern</span>
</span>
Something like this:
The idea here is the label element which can create amazing things.
Playing with it can generate you a bunch of great effects.
You just need to hide the radios or checkboxes and work with its labels, and you need to know three important css selectors for this effect:
The general next sibling: element ~ sibling{ style } which select all the sibling found after the element
The direct next sibling: element + sibling{ style } which select only the first sibling after the element
The checked input selector: input:checked{ style } which selects the input if it's checked only.
And this effect can be done with these steps:
Create an input and a label for every choice you need
Connect every input with its label using the for and id
Hide the input using something like display: none or others
Set a style for your label which will be the default mode
Set a new style for the label that placed after a checked input input:checked + lebel{ style }
Now we can apply it:
nav{
width: fit-content;
border: 1px solid #666;
border-radius: 4px;
overflow: hidden;
display: flex;
flex-direction: row;
flex-wrap: no-wrap;
}
nav input{ display: none; }
nav label{
font-family: sans-serif;
padding: 10px 16px;
border-right: 1px solid #ccc;
cursor: pointer;
transition: all 0.3s;
}
nav label:last-of-type{ border-right: 0; }
nav label:hover{
background: #eee;
}
nav input:checked + label{
background: #becbff;
}
<nav>
<input type="radio" id="x1" name="x"/>
<label for="x1">Choice 1</label>
<input type="radio" id="x2" name="x"/>
<label for="x2">Choice 2</label>
<input type="radio" id="x3" name="x"/>
<label for="x3">Choice 3</label>
<input type="radio" id="x4" name="x"/>
<label for="x4">Choice 4</label>
<!-- as many choices as you like -->
</nav>
And it's done now.
You can search for many many ideas on codepen and you can see this great navigation bar using only css and navigates throw the different pages:
Nav Bar Using Only CSS
Or See this collapsed nav bar that can be opened or closed using only css too:
Open & Close Nav Bar Using CSS
To style a checkbox or a radio button you need to hide the real input and style another element to look like the one you need. Please refer to this w3schools page for a tutorial on how to do this: https://www.w3schools.com/howto/howto_css_custom_checkbox.asp
you need to hide the real input and style another element to look like the one you need. Please refer to this
<input type='checkbox' name='checkbox-btns' id='checkbox-btn-2'/> <label htmlFor='checkbox-btn-2' class='btn'> Unsafe</label>
input[type=checkbox]{display:none;}
input[type=checkbox] + label.btn{
width:300px;
padding: 5px 5px;
text-align: center;
margin: 5px 5px;
display: inline-block;
text-transform: capitalize;
font-size: 10px;
font-weight: 600;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 1px solid #0088cc;
color: #0088cc;
-webkit-transition: none;
-moz-transition: none;
transition: none;
border-radius: 10px;
cursor: pointer;
}
input[type=checkbox]:checked + label.btn{
background: #0088cc;
color:white;
}

How can I change the size of a Bootstrap checkbox?

Wondering if its possible to change the size of checkbox as it's possible with buttons. I want it to be bigger, so it makes it easy to press. Right now its looking like this:
Code:
<div class="form-group">
<label class="col-md-7 control-label">Kalsiumklorid: </label>
<div class="col-md-5" >
{{ Form::checkbox('O_Kals_Klor', 1 , array('class' => 'form-control' )) }}
</div>
</div>
Or you can style it with pixels.
.big-checkbox {width: 30px; height: 30px;}
input[type=checkbox]
{
/* Double-sized Checkboxes */
-ms-transform: scale(2); /* IE */
-moz-transform: scale(2); /* FF */
-webkit-transform: scale(2); /* Safari and Chrome */
-o-transform: scale(2); /* Opera */
padding: 10px;
}
It is possible in css, but not for all the browsers.
The effect on all browsers:
http://www.456bereastreet.com/lab/form_controls/checkboxes/
A possibility is a custom checkbox with javascript:
http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/
Following works in bootstrap 4 and displays well in CSS, mobile and has no issues with label spacing.
CSS
.checkbox-lg .custom-control-label::before,
.checkbox-lg .custom-control-label::after {
top: .8rem;
width: 1.55rem;
height: 1.55rem;
}
.checkbox-lg .custom-control-label {
padding-top: 13px;
padding-left: 6px;
}
.checkbox-xl .custom-control-label::before,
.checkbox-xl .custom-control-label::after {
top: 1.2rem;
width: 1.85rem;
height: 1.85rem;
}
.checkbox-xl .custom-control-label {
padding-top: 23px;
padding-left: 10px;
}
HTML
<div class="custom-control custom-checkbox checkbox-lg">
<input type="checkbox" class="custom-control-input" id="checkbox-3">
<label class="custom-control-label" for="checkbox-3">Large checkbox</label>
</div>
You can also make it extra large by declaring checkbox-xl
If anyone from BS team is reading this, it would be really good if you make this available right out of the box, I don't see anything for it in BS 5 either
source
It is possible to implement custom bootstrap checkbox for the most popular browsers nowadays.
You can check my Bootstrap-Checkbox project in GitHub, which contains simple .less file.
There is a good article in MDN describing some techniques, where the two major are:
Label redirects a click event.
Label can redirect a click event to its target if it has the for attribute like in <label for="target_id">Text</label> <input id="target_id" type="checkbox" />, or if it contains input as in Bootstrap case: <label><input type="checkbox" />Text</label>.
It means that it is possible to place a label in one corner of the browser, click on it, and then the label will redirect click event to the checkbox located in other corner producing check/uncheck action for the checkbox.
We can hide original checkbox visually, but make it is still working and taking click event from the label. In the label itself we can emulate checkbox with a tag or pseudo-element :before :after.
General non supported tag for old browsers
Some old browsers does not support several CSS features like selecting siblings p+p or specific search input[type=checkbox]. According to the MDN article browsers that support these features also support :root CSS selector, while others not. The :root selector just selects the root element of a document, which is html in a HTML page. Thus it is possible to use :root for a fallback to old browsers and original checkboxes.
Final code snippet:
:root {
/* larger checkbox */
}
:root label.checkbox-bootstrap input[type=checkbox] {
/* hide original check box */
opacity: 0;
position: absolute;
/* find the nearest span with checkbox-placeholder class and draw custom checkbox */
/* draw checkmark before the span placeholder when original hidden input is checked */
/* disabled checkbox style */
/* disabled and checked checkbox style */
/* when the checkbox is focused with tab key show dots arround */
}
:root label.checkbox-bootstrap input[type=checkbox] + span.checkbox-placeholder {
width: 14px;
height: 14px;
border: 1px solid;
border-radius: 3px;
/*checkbox border color*/
border-color: #737373;
display: inline-block;
cursor: pointer;
margin: 0 7px 0 -20px;
vertical-align: middle;
text-align: center;
}
:root label.checkbox-bootstrap input[type=checkbox]:checked + span.checkbox-placeholder {
background: #0ccce4;
}
:root label.checkbox-bootstrap input[type=checkbox]:checked + span.checkbox-placeholder:before {
display: inline-block;
position: relative;
vertical-align: text-top;
width: 5px;
height: 9px;
/*checkmark arrow color*/
border: solid white;
border-width: 0 2px 2px 0;
/*can be done with post css autoprefixer*/
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
}
:root label.checkbox-bootstrap input[type=checkbox]:disabled + span.checkbox-placeholder {
background: #ececec;
border-color: #c3c2c2;
}
:root label.checkbox-bootstrap input[type=checkbox]:checked:disabled + span.checkbox-placeholder {
background: #d6d6d6;
border-color: #bdbdbd;
}
:root label.checkbox-bootstrap input[type=checkbox]:focus:not(:hover) + span.checkbox-placeholder {
outline: 1px dotted black;
}
:root label.checkbox-bootstrap.checkbox-lg input[type=checkbox] + span.checkbox-placeholder {
width: 26px;
height: 26px;
border: 2px solid;
border-radius: 5px;
/*checkbox border color*/
border-color: #737373;
}
:root label.checkbox-bootstrap.checkbox-lg input[type=checkbox]:checked + span.checkbox-placeholder:before {
width: 9px;
height: 15px;
/*checkmark arrow color*/
border: solid white;
border-width: 0 3px 3px 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<p>
Original checkboxes:
</p>
<div class="checkbox">
<label class="checkbox-bootstrap">
<input type="checkbox">
<span class="checkbox-placeholder"></span>
Original checkbox
</label>
</div>
<div class="checkbox">
<label class="checkbox-bootstrap">
<input type="checkbox" disabled>
<span class="checkbox-placeholder"></span>
Original checkbox disabled
</label>
</div>
<div class="checkbox">
<label class="checkbox-bootstrap">
<input type="checkbox" checked>
<span class="checkbox-placeholder"></span>
Original checkbox checked
</label>
</div>
<div class="checkbox">
<label class="checkbox-bootstrap">
<input type="checkbox" checked disabled>
<span class="checkbox-placeholder"></span>
Original checkbox checked and disabled
</label>
</div>
<div class="checkbox">
<label class="checkbox-bootstrap checkbox-lg">
<input type="checkbox">
<span class="checkbox-placeholder"></span>
Large checkbox unchecked
</label>
</div>
<br/>
<p>
Inline checkboxes:
</p>
<label class="checkbox-inline checkbox-bootstrap">
<input type="checkbox">
<span class="checkbox-placeholder"></span>
Inline
</label>
<label class="checkbox-inline checkbox-bootstrap">
<input type="checkbox" disabled>
<span class="checkbox-placeholder"></span>
Inline disabled
</label>
<label class="checkbox-inline checkbox-bootstrap">
<input type="checkbox" checked disabled>
<span class="checkbox-placeholder"></span>
Inline checked and disabled
</label>
<label class="checkbox-inline checkbox-bootstrap checkbox-lg">
<input type="checkbox" checked>
<span class="checkbox-placeholder"></span>
Large inline checked
</label>
I used just "save in zoom", in example:
.my_checkbox {
width:5vw;
height:5vh;
}
I have used this library with sucess
http://plugins.krajee.com/checkbox-x
It requires jQuery and bootstrap 3.x
Download the zip here: https://github.com/kartik-v/bootstrap-checkbox-x/zipball/master
Put the contents of the zip in a folder within your project
Pop the needed libs in your header
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link href="path/to/css/checkbox-x.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="path/to/js/checkbox-x.min.js" type="text/javascript"></script>
Add the data controls to the element using the data-size="xl" to change the size as shown here http://plugins.krajee.com/cbx-sizes-demo
<label for="element_id">CheckME</label>
<input type="checkbox" name="my_element" id="element_id" value="1" data-toggle="checkbox-x" data-three-state="false" data-size="xl"/>
There are numerous other features as well if you browse the plugin site.
<div id="rr-element">
<label for="rr-1">
<input type="checkbox" value="1" id="rr-1" name="rr[]">
Value 1
</label>
</div>
//do this on the css
div label input { margin-right:100px; }
just use simple css
.big-checkbox {width: 1.5rem; height: 1.5rem;top:0.5rem}
Aqui lo que me ayudo a solucionarlo:
.checkbox-xl .form-check-input
{
scale: 2.5;
}
.checkbox-xl .form-check-label
{
padding-left: 25px;
}
<div class="form-check checkbox-xl">
<input class="form-check-input" type="checkbox" value="1" id="checkbox-3" name="check1"/>
<label class="form-check-label" for="checkbox-3">Etiqueta</label>
</div>

How to show multiple font colors inside the Text Field

i want text inside the text field like "your name* "
the color of "your name" should be black and the color of * should be red.
how can i do this??
Please help me.
You cannot; the value of a text input field is plain text.
Put the explanation, including the requiredness indicator if desired, in a label, not into the field. The you can use markup for the indicator, and color it:
<label for=name>Your name<span class=reqd>*</span>:</label>
<input id=name name=name size=40 required>
I think you should want this
CSS
label{
color:black;
}
label span {
color:red;
}
input{
line-height:25px;
color:gray;
font-size:16px;
}
input:focus{
color:black;
}
HTML
<label>
Your Name:- <input type="text" value="your name"><span>*</span>
</label>
Live demo http://jsfiddle.net/rohitazad/dZmaZ/
You can't have different colours in one text box. (Reliably across browsers anyway)
The most common approach to this issue for required fields is to place the asterisk directly after the text box in an element with a class to set the text to red.
Example: http://jsfiddle.net/JzFd4/
This is what i was asking here in question.
Multiple Colors Placeholder.
Answer Link Here
Some Trick here
.input-field {
position: relative;
display: inline-block;
}
.input-field > label {
position: absolute;
left: 0.5em;
top: 50%;
margin-top: -0.5em;
opacity: 0.5;
}
.input-field > input[type=text]:focus + label {
display: none;
}
.input-field > label > span {
letter-spacing: -2px;
}
.first-letter {
color: red;
}
.second-letter {
color: blue;
<div class="input-field">
<input id="input-text-field" type="text"></input>
<label for="input-text-field">
<span class="first-letter">your name</span>
<span class="second-letter">*</span>
</label>
</div>

Radio button formatting in IE8 (not displaying correctly)

I'm having a problem with getting my radio buttons laid out (and checkboxes) correctly in IE8 .. Firefox, Chrome, Opera all working however ..
Here is a screenshot of the problem
The code is below:
.row input (line 471) {
float: left;
display: inline;
width: 16px;
height: 16px;
margin-top: 0pt;
margin-right: 5px;
margin-bottom: 0pt;
margin-left: 0pt;
}
.row label (line 479) {
float: none;
font-weight: normal;
font-size: 12px;
line-height: 16px;
}
div.panes label (line 70) {
font-size: 95%;
font-weight: bold;
color: #222222;
line-height: 150%;
padding-bottom: 3px;
display: block;
}
<label for="AdditionalResponses_0__Response" id="AdditionalResponses_0__Response_Label">Single answer</label>
<div class="row " id="AdditionalResponses_0__Response">
<input id="AdditionalResponses_0__Response_one" name="AdditionalResponses[0].Response" type="radio" value="one" />
<label for="AdditionalResponses_0__Response_one" id="AdditionalResponses_0__Response_one_Label">one</label>
<input id="AdditionalResponses_0__Response_two" name="AdditionalResponses[0].Response" type="radio" value="two" />
<label for="AdditionalResponses_0__Response_two" id="AdditionalResponses_0__Response_two_Label">two</label>
<input id="AdditionalResponses_0__Response_three" name="AdditionalResponses[0].Response" type="radio" value="three" />
<label for="AdditionalResponses_0__Response_three" id="AdditionalResponses_0__Response_three_Label">three</label>
<input id="AdditionalResponses_0__Response_four" name="AdditionalResponses[0].Response" type="radio" value="four" />
<label for="AdditionalResponses_0__Response_four" id="AdditionalResponses_0__Response_four_Label">four</label>
</div>
Sorry for the one long line, but that's how I got it through the source..
Try removing the height or float from .row input.
Avoid adjusting the line-height if you can, as well.
Looks like another case of IE Stepdown: Preventing Menu Stepdown
Are you trying to align them vertically or horizontally?
If vertically, add this to your css
.row label {
display: block;
}
and change your markup so that your inputs are wrapped by the labels. You wouldn't have to use the for="" attribute this way.
<label>
<input id="AdditionalResponses_0__Response_one" name="AdditionalResponses[0].Response" type="radio" value="one" />
one
</label>
If horizontally, add
.row input, .row label {
float: left;
display: block;
}
Im not sure but - did you try the clear property?
in your case the value would be left i think
w3 source

Resources