give css to checkbox - html

I am new to CSS.
I want to give CSS to checkbox just shown in the image.
i have tried but checkbox is appearing on the screen and when I select one of the category then it background would be yellow.
Thank You.
.radio_toggle {
float:left;
}
.radio_toggle label {
float:left;
width:100px;
overflow:auto;
}
.radio_toggle label span {
text-align:center;
font-size: 15px;
padding:5px 0px;
display:block;
}
.radio_toggle label input {
position:absolute;
}
.radio_toggle .venue {
background-color:#edf1f2;
color: #58666e;
min-height: 100% !important;
border: thin #ced9db solid;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
<div class="categories">
<div class="radio_toggle">
<label class="venue" style="">
<input type="checkbox" name="toggle">
<span>Category</span>
</label>
</div>
</div>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style="">
<input type="checkbox" name="toggle">
<span>Category</span>
</label>
</div>
</div>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style="">
<input type="checkbox" name="toggle">
<span>Category</span>
</label>
</div>
</div>

To hide the input, give it display: none;, updated CSS rule
.radio_toggle label input {
display: none;
}
To give the button a color use the :checked selector, added CSS rule
.radio_toggle label input:checked + span {
color: white;
background: gold;
}
Sample
.radio_toggle {
float:left;
}
.radio_toggle label {
float:left;
width:100px;
overflow:auto;
}
.radio_toggle label span {
text-align:center;
font-size: 15px;
padding:5px 0px;
display:block;
}
.radio_toggle .venue {
background-color:#edf1f2;
color: #58666e;
min-height: 100% !important;
border: thin #ced9db solid;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
.radio_toggle label input {
display: none;
}
.radio_toggle label input:checked + span {
color: white;
background: gold;
}
<div class="categories">
<div class="radio_toggle">
<label class="venue" style="">
<input type="checkbox" name="toggle">
<span>Category</span>
</label>
</div>
</div>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style="">
<input type="checkbox" name="toggle">
<span>Category</span>
</label>
</div>
</div>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style="">
<input type="checkbox" name="toggle">
<span>Category</span>
</label>
</div>
</div>

As pointed by #UnknownDeveloper, you have to use javascript for that.
Make a new class .venue_selected and give your desired colors. Then use click event for all elements to add class to label and check respective checkbox.
<style type="text/css">
.radio_toggle {
float:left;
}
.radio_toggle label {
float:left;
width:100px;
overflow:auto;
}
.radio_toggle label span {
text-align:center;
font-size: 15px;
padding:5px 0px;
display:block;
}
.radio_toggle label input {
position:absolute;
}
.radio_toggle .venue {
background-color:#edf1f2;
color: #58666e;
/*min-height: 100% !important;*/
border: thin #ced9db solid;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
cursor: pointer;
}
.radio_toggle .venue_selected{
background: #f9d342 !important;
color: #ffffff !important;
}
.categories input[type="checkbox"] {
display: none;
}
</style>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style=""><input type="checkbox" name="toggle"><span>Category</span></label>
</div>
</div>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style=""><input type="checkbox" name="toggle"><span>Category</span></label>
</div>
</div>
<div class="categories">
<div class="radio_toggle">
<label class="venue" style=""><input type="checkbox" name="toggle"><span>Category</span></label>
</div>
</div>
<script type="text/javascript">
var elms = document.querySelectorAll("label.venue");
elms.forEach(function(el,i) {
el.onclick = function() {
console.log(el);
el.classList.toggle("venue_selected");
el.querySelector("input[type='checkbox']").click();
}
});
</script>

You can accomplish this using 2 methods.
Either using JavaScript or CSS.
For CSS it's very simple. You have to use the :checked attribute.
.radio_toggle[type=checkbox] + label {
// Code on how to look before checked
}
input[type=checkbox]:checked + label {
// Code on how to look after checked
}
For JS you first have to get the radio_toggle element using and then listen for if it's checked which for your case will look something like this
var element = document.getElementsByClassName("radio_toggle").checked = true;
function check(element) {
element.checked = true;
element.style.color = "Color you desire"
}

Related

keep colored tab button with css only

i everyone!
I need help, I would like the tabs:
tab1 - tab2 - tab3 remained white after clicking, now in my code in hover it turns white, but then everything vanishes.
How can I do with only css, because js does not support me the system?
Any advice and help is welcome!
Thank you all!!
<style>
body {
font-family:"Open Sans";
background:white;
height:300px;
font-size:14px;
}
.tab section {
display:none;
}
.tab section:target, .tab section:last-of-type {
display:block;
}
.tab section:target~section {
display:none;
}
.L1 {
padding:17px;
border:1px solid #2c3e50;
color:white !important;
padding-left:10px;
padding-right:10px;
margin-left:-1px;
}
.L1:hover {
background-color:white;
color:black !important;
border-bottom:1px solid white;
padding:17px;
padding-left:10px;
padding-right:10px;
}
</style>
<section class="tab" style="border:none;background:#1abc9c;max-width:46.5rem;width:100%;margin:5px auto;height:51px;line-height:51px;">
<a class="L1" href="#tab1">tab1</a>
<a class="L1" href="#tab2" style="margin-left:-5px;">tab2</a>
<a class="L1" href="#tab3" style="margin-left:-5px;">tab3</a>
<section id="tab2" style="margin-top:-60px !important;padding-top:61px;">
<span >hello2</span>
</section>
<section id="tab3" style="margin-top:-60px !important;padding-top:61px;">
<span>hello3</span>
</section>
<section id="tab1" style="margin-top:-60px !important;padding-top:61px;">
<span >hello1</span>
</section>
</section>
input, .content {
display: none;
background: #1f7507;
line-height: 25px;
padding: 5px 25px;
color: #fff;
font: normal 1em/150% Sans-Serif;
min-width: 200px;
}
#one:checked ~ .one,
#two:checked ~ .two,
#three:checked ~ .three {display: block;}
label {
cursor: pointer;
background: #999;
height: 25px;
padding: 5px 10px;
display: inline-block;
text-align: center;
color: #fff;
font: normal 1em/150% Sans-Serif;
margin-right: -3px;
transition: background .25s linear;
}
label:hover, input:checked + label {background: #1f7507;}
h3, p {
text-indent: 25px;
text-align: justify;
}
<input type="radio" name="nav" id="one" checked="checked"/>
<label for="one">tab 1</label>
<input type="radio" name="nav" id="two"/>
<label for="two">tab 2</label>
<input type="radio" name="nav" id="three"/>
<label for="three">tab 3</label>
<article class="content one">
<h3>sample 1</h3>
<p>heyyy</p>
</article>
<article class="content two">
<h3>sample 2</h3>
<p>howdy</p>
</article>
<article class="content three">
<h3>sample 3</h3>
<p>hello</p>
</article>

Why cant I type in the text box of the second form

Im trying to make two froms on one page. one right underneather the other. The first form is to put the main information in and then the second form is suppossed to be a report. The problem is that the second form wont allow any text to be put into the text box, it doesnt even seem to regonise that there is a text box on the page.
Any ideas why this might be happening?
Thanks
* {
box-sizing: border-box;
}
#tl {
padding: 1em;
background: #f9f9f9;
border: 1px solid #c1c1c1;
margin-top: 2rem;
width: 1400px;
height:190px;
margin-left: auto;
margin-right: auto;
padding: 1em;
text-transform: uppercase;
}
#tl input {
margin-bottom: 1rem;
background: #fff;
border: 1px solid #9c9c9c;
}
#report {
padding: 1em;
background: #f9f9f9;
border: 1px solid #c1c1c1;
margin-top: 2rem;
width: 1400px;
height:690px;
margin-left: auto;
margin-right: auto;
padding: 1em;
text-transform: uppercase;
}
#report input {
margin-bottom: 1rem;
background: #fff;
border: 1px solid #9c9c9c;
}
.fdate{
position:relative;
left:60px;
top:30px;
}
.fsales{
position:relative;
left:320px;
bottom:22px;
}
.fservice{
position:relative;
left:650px;
bottom:75px;
}
.fpart{
position:relative;
left:1000px;
bottom:127px;
}
.fqty{
position:relative;
left:20px;
bottom:120px;
}
.fhour{
position:relative;
left:376px;
bottom:175px;
}
.fcust{
position:relative;
left:691px;
bottom:225px;
}
.fname{
position:relative;
left:1068px;
bottom:280px;
}
.inputs{
position:relative;
top: 20px;
}
.title1{
position:relative;
bottom:430px;
left:500px;
}
<!--form for top level info-->
<div id = "tl">
<form>
<div class = "inputs">
<div class="fdate">
<label for="fdate">Date:</label>
<input type="text" id="fdate" name="fdate"><br><br>
</div>
<div class="fsales">
<label for="fsales">Sales Order:</label>
<input type="text" id="fsales" name="fsales"><br><br>
</div>
<div class="fservice">
<label for="fservice">Service Order:</label>
<input type="text" id="fservice" name="fservice"><br><br>
</div>
<div class="fpart">
<label for="fpart">Part Number:</label>
<input type="text" id="fpart" name="fpart"><br><br>
</div>
<div class="fqty">
<label for="fqty">Quantity:</label>
<input type="text" id="fqty" name="fqty"><br><br>
</div>
<div class="fhour">
<label for="fhour">Hours:</label>
<input type="text" id="fhour" name="fhour"><br><br>
</div>
<div class="fcust">
<label for="fcust">Customer:</label>
<input type="text" id="fcust" name="fcust"><br><br>
</div>
<div class="fname">
<label for="fname">Name:</label>
<input type="text" id="fname" name="fname"><br><br>
</div>
</div>
<div class = "title1">
<div> Missing & Damaged Report</div>
</div>
</form>
</div>
<!--second form for missing parts-->
<div id = "report">
<form>
<div class="P1">
<label for="P1">Part Number:</label>
<input type="text" id="P1" name="P1"><br><br>
</div>
</form>
</div>
The problem is postion:relative; to input class see work example:
* {
box-sizing: border-box;
}
#tl {
padding: 1em;
background: #f9f9f9;
border: 1px solid #c1c1c1;
margin-top: 2rem;
width: 1400px;
height:190px;
margin-left: auto;
margin-right: auto;
padding: 1em;
text-transform: uppercase;
}
#tl input {
margin-bottom: 1rem;
background: #fff;
border: 1px solid #9c9c9c;
}
#report {
padding: 1em;
background: #f9f9f9;
border: 1px solid #c1c1c1;
margin-top: 2rem;
width: 1400px;
height:690px;
margin-left: auto;
margin-right: auto;
padding: 1em;
text-transform: uppercase;
}
#report input {
margin-bottom: 1rem;
background: #fff;
border: 1px solid #9c9c9c;
}
.fdate{
position:relative;
left:60px;
top:30px;
}
.fsales{
position:relative;
left:320px;
bottom:22px;
}
.fservice{
position:relative;
left:650px;
bottom:75px;
}
.fpart{
position:relative;
left:1000px;
bottom:127px;
}
.fqty{
position:relative;
left:20px;
bottom:120px;
}
.fhour{
position:relative;
left:376px;
bottom:175px;
}
.fcust{
position:relative;
left:691px;
bottom:225px;
}
.fname{
position:relative;
left:1068px;
bottom:280px;
}
.inputs{
top: 20px;
}
.title1{
position:relative;
bottom:430px;
left:500px;
}
<!--form for top level info-->
<div id = "tl">
<form>
<div class = "inputs">
<div class="fdate">
<label for="fdate">Date:</label>
<input type="text" id="fdate" name="fdate"><br><br>
</div>
<div class="fsales">
<label for="fsales">Sales Order:</label>
<input type="text" id="fsales" name="fsales"><br><br>
</div>
<div class="fservice">
<label for="fservice">Service Order:</label>
<input type="text" id="fservice" name="fservice"><br><br>
</div>
<div class="fpart">
<label for="fpart">Part Number:</label>
<input type="text" id="fpart" name="fpart"><br><br>
</div>
<div class="fqty">
<label for="fqty">Quantity:</label>
<input type="text" id="fqty" name="fqty"><br><br>
</div>
<div class="fhour">
<label for="fhour">Hours:</label>
<input type="text" id="fhour" name="fhour"><br><br>
</div>
<div class="fcust">
<label for="fcust">Customer:</label>
<input type="text" id="fcust" name="fcust"><br><br>
</div>
<div class="fname">
<label for="fname">Name:</label>
<input type="text" id="fname" name="fname"><br><br>
</div>
</div>
<div class = "title1">
<div> Missing & Damaged Report</div>
</div>
</form>
</div>
<!--second form for missing parts-->
<div id = "report">
<form>
<div class="P1">
<label for="P1">Part Number:</label>
<input type="text" id="P1" name="P1"><br><br>
</div>
</form>
</div>

radio button - align background image and text

I'm having a problem align my custom radio button and text (see image)
I've use css for my radio buttons and can't seem to align them .
here's my HTML :
label.item {
display: inline-block;
position: relative;
}
label.item > input {
visibility: hidden;
position: absolute;
}
label.item > .radio-image::before {
content: url("../tools/unchecked.png");
}
label.item > input[type="radio"]:checked + .radio-image::before {
content: url("../tools/checked.png");
}
label.item > input[type="radio"]:hover + .radio-image::before{
cursor: pointer;
}
<div class = "container">
<div class = "form-group">
<label>Body</label>
<label class="item">
<input type="radio" value="Good/Minor Flaws" name="size" required="required" />
<div class="radio-image text-center">Good / Minor Flaws</div>
</label>
<label class="item">
<input type="radio" value="Major Damage" name="size" required="required"/>
<div class="radio-image text-center">Major Damage </div>
</label>
</div>
</div>
https://jsfiddle.net/h2q7y4uj/#&togetherjs=ADTFQvN22E
Here you go with a solution https://jsfiddle.net/h2q7y4uj/4/
div.item {
display: inline-block;
position: relative;
}
div.item > input {
visibility: hidden;
position: absolute;
}
div.item > .radio-image::before {
content: url(http://via.placeholder.com/50x50);
}
div.item > input[type="radio"]:checked + .radio-image::before {
content: url(http://via.placeholder.com/51x51);
}
div.item > input[type="radio"]:hover + .radio-image::before {
cursor: pointer;
}
.radio-image {
position: relative;
width: 200px;
}
.radio-image > span{
position: absolute;
top: 45%;
transform: translateY(-50%);
}
<div class="container">
<div class="form-group">
<label>Body</label>
<div class="item">
<input type="radio" value="Good/Minor Flaws" name="size" required="required" />
<div class="radio-image text-center">
<span>Good / Minor Flaws</span></div>
</div>
<div class="item">
<input type="radio" value="Major Damage" name="size" required="required" />
<div class="radio-image text-center">
<span>Major Damage</span> </div>
</div>
</div>
</div>
Hope this will help you.
Just update following css code
.radio-image {
display: inline-block;
line-height: 30px;
}
label.item>.radio-image::before {
content: url("../tools/unchecked.png");
float: left;
line-height: 30px;
display: inline-block;
padding-right: 5px;
}

Adding Currency Value in Css puts it onto seperate line

I've added the following to the css and html file:
.currencyinput {
border: 1px inset #eee;
}
.currencyinput input {
border: 0;
}
<td><span class="currencyinput">$<input type="text" name="amount"></span></td>
And my resulting page shows the $ and then the textbox on a new line below it. I was intending the $ to be in the textbox.
Appreciate any insight on this. Thanks!
Consider simulating an input field with a fixed using a span with a border around a border less input field. Here's a basic example:
<div class="container">
<h3>Basic form example</h3>
<div class="form-group">
<div class="input-icon">
<i>$</i>
<input type="text" class="form-control" placeholder="0.00">
</div>
</div>
<div class="form-group">
<div class="input-icon input-icon-right">
<i>€</i>
<input type="text" class="form-control" placeholder="0.00">
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="fa fa-bitcoin"></i>
<input type="text" class="form-control" placeholder="0.00">
</div>
</div>
<h3>Example using <code>form-inline</code></h3>
<div class="alert alert-danger visible-xs">This window needs to be made
larger to see the inline example.</div>
<form class="form-inline">
Some text here
<div class="form-group input-icon">
<i>$</i>
<input type="text" class="form-control" placeholder="0.00">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
CSS:
.input-icon {
position: relative;
}
.input-icon > i {
position: absolute;
display: block;
transform: translate(0, -50%);
top: 50%;
pointer-events: none;
width: 25px;
text-align: center;
font-style: normal;
}
.input-icon > input {
padding-left: 25px;
padding-right: 0;
}
.input-icon-right > i {
right: 0;
}
.input-icon-right > input {
padding-left: 0;
padding-right: 25px;
text-align: right;
}
use this css for remove focus border input:focus{outline: none;}
.currencyinput span{
position: relative;
}
.currencyinput input{
padding-left:20px;
}
.currencyinput span{
left:15px;
top:0
position: absolute;
}
.currencyinput input:focus {
outline: none;
}
<span class="currencyinput"><span>$</span><input type="text" name="amount"></span>

How to apply CSS on texte label beside an input?

I have this small code contains a text (label) and a text input
What I am looking for is to have text + input take 100% of the div (i.e 20% for text and 80% for input) and the text should be in the middle of its zone with a background has the same height as the input.
I tried with span, with applying background-color: blue; on the div but It didn't have any impact.
Do you know ho to do it?
Thank you in advance.
#zoneFiltre {
width: 100%;
}
.champs {
width:20%;
background-color: blue;
text-align: middle;
color: white;
}
#filtreMultiAptitudes{
width:80%;
float:right;
}
<div id="listeMultiAptitude">
<div class="zoneFiltre">
<label class="champs">filter: </label>
<input type="text" id="filtreMultiAptitudes" />
</div>
</div>
If you want to use Flexbox you can use flex: 0 0 80% on input and flex: 1 on label also its text-align: center
.zoneFiltre {
display: flex;
}
.champs {
flex: 1;
background-color: blue;
text-align: center;
color: white;
}
#filtreMultiAptitudes {
flex: 0 0 80%;
}
<div id="listeMultiAptitude">
<div class="zoneFiltre">
<label class="champs">filter: </label>
<input type="text" id="filtreMultiAptitudes" />
</div>
</div>
This is because <label> tag is an inline element so it cannot take width/height. Display it as inline-block.
body{
margin: 0;
}
#zoneFiltre {
width: 100%;
}
.champs {
display: inline-block;
width:20%;
background-color: blue;
color: white;
}
#filtreMultiAptitudes{
display: inline-block;
width:79.3%;
float:right;
}
<div id="listeMultiAptitude">
<div class="zoneFiltre">
<label class="champs">filter: </label>
<input type="text" id="filtreMultiAptitudes" />
</div>
</div>
The space between both elements is because the <input> tag has a default border. You can use a lower percentage (as shown above) or use calc function to rest the width that occupy the border.
body{
margin: 0;
}
#zoneFiltre {
width: 100%;
}
.champs {
display: inline-block;
width:20%;
background-color: blue;
color: white;
}
#filtreMultiAptitudes{
display: inline-block;
width: calc(80% - 4px);
float:right;
}
<div id="listeMultiAptitude">
<div class="zoneFiltre">
<label class="champs">filter: </label>
<input type="text" id="filtreMultiAptitudes" />
</div>
</div>
Another solution and the best in my opinion is to use box-sizing: border-box which calculates the width taking as part of the width the borders and paddings of an element.
body{
margin: 0;
}
#zoneFiltre {
width: 100%;
}
.champs {
display: inline-block;
width:20%;
background-color: blue;
color: white;
}
#filtreMultiAptitudes{
display: inline-block;
width: 80%;
box-sizing: border-box;
float:right;
}
<div id="listeMultiAptitude">
<div class="zoneFiltre">
<label class="champs">filter: </label>
<input type="text" id="filtreMultiAptitudes" />
</div>
</div>
You can use display:table if you fancy this.
form {
display:table;
border:1px dotted black;
width:100%;
}
form p {
display:table-row;
}
label, form span {
display:table-cell;
padding:0.5em 0;
}
label {
background:blue;
color:white;
vertical-align:top;
}
span input, span textarea {
box-sizing:border-box;
width:100%;
}
textarea {
display:block;
}
<form>
<p>
<label for="input1">A label: </label>
<span><input type="text" id="input1" /></span>
</p>
<p>
<label for="input2">A longer label:</label>
<span><input type="text" id="input2" /></span>
</p>
<p>
<label for="txt">Textarea:</label>
<span><textarea id="txt" rows="5" cols="15"></textarea></span>
</p>
</form>