How to put a custom image instead of checkbox next to text? - html

.selected_area {
background-color: #c8c8c8;
height: 330px;
border-radius: 5px;
width:233px;
margin-top:5px;
}
.selected_area label input[type="checkbox"] {
display:none;
}
.selected_area label input[type="checkbox"] + .label-text:before {
content: url("../images/xxx.png");
speak: none;
font-style: noraml;
font-size: normal;
font-variant: normal;
font-transform: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
/*width: em;*/
/*display: inline-block;*/
margin-right: 10px;
}
.selected_area label input[type="checkbox"]:checked + .label-text:before {
content: url("../images/xxx.png");
}
<div class="selected_area">
<label>
<input type="checkbox" value="scooter" id="">
<div class="label-text"><span>This is a testThis is a testThis is a testThis is a testThis is a testThis is a test</span></div>
</label>
</div>
Now I am using my image instead of original checkbox image.
The result was not perfect.
How do I do to make my text next to my image and if the text is too long, it will display on next line but still next to image not under it?

I hope this is what you expect. Get rid of your <span> element and put your text under a separate div. Then float the image and text div to the left and apply a margin-left to the text div so that it will not overlap with the image.
.selected_area {
background-color: #c8c8c8;
height: 330px;
border-radius: 5px;
width: 233px;
margin-top: 5px;
}
.selected_area label input[type="checkbox"] {
display: none;
}
.label-text{
float: left;
display: inline-block;
word-break: break-all;
}
#text{
margin-left: 25px;
}
.selected_area label input[type="checkbox"] + .label-text:before {
content: url("http://files.softicons.com/download/toolbar-icons/black-wireframe-toolbar-icons-by-gentleface/png/16/checkbox_unchecked.png");
speak: none;
font-style: noraml;
font-size: normal;
font-variant: normal;
font-transform: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
/*width: em;*/
/*display: inline-block;*/
margin-right: 10px;
}
.selected_area label input[type="checkbox"]:checked + .label-text:before {
content: url("http://files.softicons.com/download/toolbar-icons/black-wireframe-toolbar-icons-by-gentleface/png/16/checkbox_checked.png");
}
<div class="selected_area">
<label style="display: inline">
<input type="checkbox" value="scooter" id="">
<div class="label-text">
</div>
<div id="text">This is a testThis is a testThis is a testThis is a testThis is a testThis is a test</div>
</label>
</div>

This is what I have for one of my page where I have a custom checkbox, just giving an example
input[type="checkbox"]{
vertical-align:middle;
margin:-3px 5px 0 0;
background: #fff;
height:17px;
width:17px;
opacity: 0;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
input[type="checkbox"]+label:before{
content:"";
display:inline-block;
margin:-3px 8px 0 -25px;
vertical-align:middle;
height:17px;
width:17px;
}
input[type="checkbox"]+label:before{
background:url(image url) {position to box};
}
input[type="checkbox"]:checked+label:before{
background:url(image url){position to box with tick};
}

I have done the needed using a checkbox hack , do check it out :
Html :
<label class="myCheckbox">
<input type="checkbox" name="test"/>
<span></span>
</label>
<p>This is test</p>
CSS :
.myCheckbox {
float: left;
}
`.myCheckbox input {
display: none;
}`
`.myCheckbox span {
width: 20px;
height: 20px;
display: block;
background: url("http://www.findanyfloor.com/pub/images/checkbox.png");
}`
`.myCheckbox input:checked + span {
background: url("http://2.bp.blogspot.com/-FBS0AYl_Gug/Uo5bW7XztnI/AAAAAAAADrA/vIr35ivrZOM/s1600/Checkbox+icon+image_small.png");
}`
I hope it solves your query.

Related

css can't change checkbox background color

I'm learning css and html, I'm validating a registration form, I have the user terms checkbox but I can't change the background color:
This is the html code where I create the checkbox and the label:
<div class="checkbox-wrap checkbox-primary" id="checkboxdiv" name="checkboxdiv">
<input class="checkbox" type="checkbox" value="0" name="termsNewUser" id="termsNewUser">
<label class="checkbox-wrap checkbox-primary" for="termsNewUser" id="termsNewUserL" name="termsNewUserL">I do accept the <u>Terms and Conditions</u> of your site.
</label>
</div>
I tried some solutions like:
input[type="checkbox"] {
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
accent-color: #9d3039;
}
And:
input[type=checkbox] {
transform: scale(1.5);
}
input[type=checkbox] {
width: 30px;
height: 30px;
margin-right: 8px;
cursor: pointer;
font-size: 17px;
visibility: hidden;
}
input[type=checkbox]:after,
input[type=checkbox]::after {
content: " ";
background-color: #fff;
display: inline-block;
margin-left: 10px;
padding-bottom: 5px;
color: #00BFF0;
width: 22px;
height: 25px;
visibility: visible;
border: 1px solid #00BFF0;
padding-left: 3px;
border-radius: 5px;
}
input[type=checkbox]:checked:after,
input[type=checkbox]:checked::after {
content: "\2714";
padding: -5px;
font-weight: bold;
}
I tried also to create a custom class and in the style.css set the accent there but nothing.
When you simply make a global definition like the one below, this color should change,
:root {
accent-color: red;
}
In your case, this change stays in the background since you have given the checkbox element visible hidden.
input[type=checkbox]:checked:after,
input[type=checkbox]:checked::after {
content: "\2714";
padding: -5px;
font-weight: bold;
background-color: red;
}
so in the checked state you can change the background color directly to get the same look.
demo https://jsfiddle.net/rjzw10cv/1/
ahh I remember having this issue. Here it is. Just change the background color and color to anything you'd like and you should be set. This can be done with any input type.
input[type="checkbox"]:checked+label:before {
background: #3d404e;
color: #F00;
content: "\2713";
text-align: center;
}
so your html code would be
<div class="checkbox-wrap checkbox-primary" id="checkboxdiv" name="checkboxdiv">
<input class="checkbox" type="checkbox" value="0" name="termsNewUser" id="termsNewUser">
<label class="checkbox-wrap checkbox-primary" for="termsNewUser" id="termsNewUserL" name="termsNewUserL">I do accept the <u>Terms and Conditions</u> of your site.
</label>
</div>
and your full css would be below, I added a margin-right:20px as to hide the large space behind the custom checkbox elements.
p {
margin: 5px 0;
padding: 0;
}
input[type="checkbox"] {
margin-right: -20px;
cursor: pointer;
font-size: 17px;
visibility: hidden;
}
label {
cursor: pointer;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR NOT CHECKED */
input[type="checkbox"]+label:before {
border: 1px solid #7f83a2;
content: "\00a0";
display: inline-block;
background: #000;
font: 16px/1em sans-serif;
height: 16px;
margin: 0 .25em 0 0;
padding: 0;
vertical-align: top;
width: 16px;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR CHECKED, CHANGE COLOR TO CHANGE CHECK MARK COLOR */
input[type="checkbox"]:checked+label:before {
background: #3d404e;
color: #ff0000;
content: "\2713";
text-align: center;
}
input[type="checkbox"]:checked+label:after {
font-weight: bold;
}
Here is a snippet:
p {
margin: 5px 0;
padding: 0;
}
input[type="checkbox"] {
margin-right: -20px;
cursor: pointer;
font-size: 17px;
visibility: hidden;
}
label {
cursor: pointer;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR NOT CHECKED */
input[type="checkbox"]+label:before {
border: 1px solid #7f83a2;
content: "\00a0";
display: inline-block;
background: #000;
font: 16px/1em sans-serif;
height: 16px;
margin: 0 .25em 0 0;
padding: 0;
vertical-align: top;
width: 16px;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR CHECKED, CHANGE COLOR TO CHANGE CHECK MARK COLOR */
input[type="checkbox"]:checked+label:before {
background: #3d404e;
color: #ff0000;
content: "\2713";
text-align: center;
}
input[type="checkbox"]:checked+label:after {
font-weight: bold;
}
<div class="checkbox-wrap checkbox-primary" id="checkboxdiv" name="checkboxdiv">
<input class="checkbox" type="checkbox" value="0" name="termsNewUser" id="termsNewUser">
<label class="checkbox-wrap checkbox-primary" for="termsNewUser" id="termsNewUserL" name="termsNewUserL">I do accept the <u>Terms and Conditions</u> of your site.
</label>
</div>

Checkbox-Trick not working

I want to use the checkbox-trick to show my mobile navbar. Somehow the h1 isn't showin up even when the invisible checkbox is checked. What have I done wrong?
#label {
margin-left: auto;
margin-right: auto;
color: #000000;
font-size: 35px;
cursor: pointer;
width: 47px;
}
h1 {
display: none
}
#toggle {
display: none;
}
#toggle:checked + h1 {
display: block;
}
<div id="hamburgermenu">
<label id="label" for="toggle">☰</label>
<input id="toggle" type="checkbox">
</div>
<h1>DEMO ELEMENT</h1>
You're using "+" which is a sibling CSS selector, but <h1> isn't a sibling of your checkbox. It's a sibling of the checkbox's parent container. You can have 3 ways to go about it.
First way: Make it the sibling of the input by placing it inside
#label {
margin-left: auto;
margin-right: auto;
color: #000000;
font-size: 35px;
cursor: pointer;
width: 47px;
}
h1 {
display: none
}
#toggle {
display: none;
}
#toggle:checked+h1 {
display: block;
}
<div id="hamburgermenu">
<label id="label" for="toggle">☰</label>
<input id="toggle" type="checkbox">
<h1>DEMO ELEMENT</h1>
</div>
Second way: Make it the sibling of the input by taking the input out of the container
#label {
margin-left: auto;
margin-right: auto;
color: #000000;
font-size: 35px;
cursor: pointer;
width: 47px;
}
h1 {
display: none
}
#toggle {
display: none;
}
#toggle:checked + h1 {
display: block;
}
<div id="hamburgermenu">
<label id="label" for="toggle">☰</label>
</div>
<input id="toggle" type="checkbox">
<h1>DEMO ELEMENT</h1>
Third way: Make use of javascript.

How to get my text on correct position next to custom checkbox?

#admin_status label {
width: 80px;
display: inline-block;
margin-right:15px;
}
#admin_status label input[type="checkbox"] {
display:none;
}
#admin_status label input[type="checkbox"] + .label-text:before {
content: url("../images/04_checkbox_radiobutton.png");
font-family: 'Roboto', sans-serif;
speak: none;
font-style: noraml;
font-size: normal;
font-variant: normal;
font-transform: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
width: 1em;
display: inline-block;
margin-right: 5px;
}
#admin_status label input[type="checkbox"]:checked + .label-text:before {
content: url("../images/04_checkbox_radiobutton_checked.png");
}
#admin_status .checkbox-inline {
width:100px;
padding-left:0px;
}
#admin_status .checkbox-inline span {
margin-left:20px;
font-size: 1em;
}
<div id="admin_status">
<label class="checkbox-inline" id="statusOpen">
<input type="checkbox" id="status" value="open"><div class="label-text"><span>Active</span></div>
</label>
<label class="checkbox-inline" id="statusClose">
<input type="checkbox" id="status" value="close"><div class="label-text"><span>Locked</span></div>
</label>
</div>
As you can see, the text next to custom checkbox image is too low.
What can I do to make them vertical-align:middle.
I try to add to css, but not working.
here is the working code with demo
Demo code
A quick and easy fix-
#admin_status .checkbox-inline span {
position:relative;
bottom: 5px;
}
Might not be the most optimal solution but will work absolutely fine.
Hope it helps.
Here's the demo if you want- JSfiddle link
First of all i would like to say that you are having too much
unnecessary codes to achieve this i don't know where you are using
that
though here i tried by changing my way here is the code please look it out
#admin_status label {
margin-right:15px;
}
.lab_check_group{
float:left;
}
input[type="checkbox"]{
float:left;
margin-right: 15px;
}
#admin_status label input[type="checkbox"] + .label-text:before {
content: url("../images/04_checkbox_radiobutton.png");
font-family: 'Roboto', sans-serif;
speak: none;
font-style: noraml;
font-size: normal;
font-variant: normal;
font-transform: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
width: 1em;
display: inline-block;
margin-right: 5px;
}
#admin_status label input[type="checkbox"]:checked + .label-text:before {
content: url("../images/04_checkbox_radiobutton_checked.png");
}
#admin_status .checkbox-inline {
width:100px;
padding-left:0px;
}
#admin_status .checkbox-inline span {
margin-left:20px;
font-size: 1em;
}
<div id="admin_status">
<div class="lab_check_group">
<label class="checkbox-inline" id="statusOpen">Active</label>
<input type="checkbox" id="status" value="open">
</div>
<div class="lab_check_group">
<label class="checkbox-inline" id="statusClose">Locked</label>
<input type="checkbox" id="status" value="close">
</div>
here is the demo working of my code
DEmo Working code

Aligning text beside a radio/checkbox in HTML

There is some padding from the top to the Keep me logged in text.
How can I remove the padding and make it look like this ?
HTML:
<div class="login-radio">
<input type="radio">Keep me logged in
</div>
CSS:
.login-radio {
font-size: 12px;
position: fixed;
left:60%;
top: 7%;
color: white;
font-family: arial;
}
Try this:
HTML:
<div>
<div class="email">
<input type="email" />
</div>
<div class="checkbox">
<input type="checkbox" />
<span>Keep me logged in</span>
</div>
</div>
CSS:
.email input {
float: left;
margin-top: 5px;
margin-left: 5px;
font-family: arial, sans-serif;
font-size: 12px;
outline: none;
}
.checkbox input {
float: left;
margin-top: 10px;
margin-left: 5px;
color: #000;
clear: both;
}
.checkbox span {
float: left;
margin-top: 7px;
margin-left: 2px;
font-family: arial, sans-serif;
}
Here's the fiddle.
Regards, Milan.
Try to use this:
HTML
<div class="login-radio radio">
<input type="radio" class="radio">
<label>Keep me logged in </label>
</div>
CSS
.login-radio, .login-checkbox, .radio, .checkbox {
display: block;
min-height: 20px;
margin-top: 10px;
margin-bottom: 0px;
padding: 0px;
margin-left: -20px;
}
input[type=checkbox] {
box-sizing: border-box;
margin: 4px 0 0;
line-height: normal;
}
.radio label, .checkbox label {
display: inline;
cursor: pointer;
}
Is this is what you want exactly the position of your radio button to be or something else
.login-radio input {
vertical-align:top;margin-top:1px;
}
http://jsfiddle.net/we9x6k3j/1/
3 steps that will fix your problem:
Remove the default margin and padding that the browser applies to the <input> by default.
Wrap the text in a <label>.
Apply vertical-align: middle to the <input> and the <label>.
Working Code Snippet:
.login-radio {
font-size: 12px;
position: fixed;
left:60%;
top: 7%;
color: black;
font-family: arial;
}
input{
margin: 0px;
padding: 0px;
}
input, label{
vertical-align: middle;
}
<div class="login-radio">
<input type="radio">
<label>Keep me logged in</label> <!-- wrap the text in a label -->
</div>
FIDDLE HERE
CSS:
.login{
width: 200px;
height:80px;
background-color: brown;
color: white;
}
.loginInput{
margin-left: 3%;
margin-top: 1%;
}
.loginRadio input{
margin-left: 3%;
vertical-align: top;
}
Key change is the vertical alignment of loginRadio input.

input checkbox check out of position

I created a custom checkbox using css3 and it turned out looking like this with the check slightly lower than where it should be...
Here is the html code applicable to this checkbox:
<div>
<input id='remember_me' type='checkbox'>
<label for='remember_me'>Remember me</label>
</div>
Here is the css code applicable to this checkbox:
input[type='checkbox'] + label:before {
content: "";
display: block;
float: left;
width: 12px;
height: 12px;
margin-right: 4px;
border: 1px solid white;
}
input[type='checkbox']:checked + label:before {
content:'✓';
color: white;
}
input[type='checkbox'] {
display: none;
}
div {
display: flex;
align-items: center;
}
Is there any way to move the check to the centre of the box?
demo - http://jsfiddle.net/victor_007/wv8ksqgL/3/
set line-height
input[type='checkbox']:checked + label:before {
content:'✓';
color: blue;
line-height: 14px;
}