Foundation 5 custom radio and checkboxes - css

How can I use custom radio buttons and checkboxes in ZURB Foundation 5? It seems like it was easy in ZURB Foundation 4, but can't get the custom radio and checkbox to work.

I don't know what have you been using before but it can be simply done by custom CSS code without JavaScript like this:
SCSS
input {
&[type=checkbox], &[type=radio] {
opacity: 0;
position: absolute;
&:checked + label:before {
background: $primary-color;
}
& + label:before {
display: inline-block;
text-align: center;
line-height: 1;
border: 0.0625rem solid $primary-color;
width: 1rem;
height: 1rem;
margin-right: 0.5rem;
font-size: 0.875rem;
color: white;
background: white;
}
}
&[type=checkbox] {
& + label:before {
content: "\2715";
padding-right: 1px;
border-radius: 0.125rem;
}
}
&[type=radio] {
& + label:before {
content: "\2713";
border-radius: 50%;
}
}
}
If you don't want to have any character inside checboxes or radio buttons then put whitespace into content attribute:
[...]
content: " ";
[...]
CodePen playground
Compiled CSS + HTML to show working example
input[type=checkbox],
input[type=radio] {
opacity: 0;
position: absolute;
}
input[type=checkbox]:checked + label:before,
input[type=radio]:checked + label:before {
background: #007095;
}
input[type=checkbox] + label:before,
input[type=radio] + label:before {
display: inline-block;
text-align: center;
line-height: 1;
border: 0.0625rem solid #007095;
width: 1rem;
height: 1rem;
margin-right: 0.5rem;
font-size: 0.875rem;
color: white;
background: white;
}
input[type=checkbox] + label:before {
content: "\2715";
padding-right: 1px;
border-radius: 0.125rem;
}
input[type=radio] + label:before {
content: "\2713";
border-radius: 50%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.0/css/foundation.min.css" rel="stylesheet"/>
<div class="row">
<div class="small-12 column">
<h3>Radio Button</h3>
<div class="inline">
<input type="radio" name="role" value="admin" id="admin" checked />
<label for="admin">admin</label>
</div>
<div class="inline">
<input type="radio" name="role" value="user" id="user" />
<label for="user">user</label>
</div>
</div>
<div class="small-12 column" style="margin-top: 10px;">
<h3>Checkbox</h3>
<input type="checkbox" id="captcha" checked/>
<label for="captcha" translate>I am human</label>
</div>
</div>

Please add this because it conflicts with the "switch"
input {
...
&.switch-input {
& + label:before {
display: none;
}
}
}

Related

how to add an image under my bootstrap and angular layout?

I have the backgroundlogin.jpg image in the assets folder of my angular project, and I would like to know how I can place it under my layout, in the white part of the figure below, where the arrows are located:
below is the project's html and ccs codes:
login.component.html:
<div class="jumbotron pt-5">
<img class="center" src="../assets/images/full-banner1.jpg">
<form class="form-signin jumbotron">
<h2 class="form-signin-heading">LOGIN</h2>
<label for="inputEmail" class="sr-only">Usuário</label>
<input name="email" [(ngModel)] = "user.username" type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Senha</label>
<input name="password" [(ngModel)] = "user.password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me">Lembrar me
</label>
</div>
<button class="btn btn-lg btn-color btn-block" (click)="validateLogin();" type="button">Entrar</button>
</form>
</div>
<footer class="footer navbar-default" role="contentinfo">
<div class="container">
<p class="absolute">
Criado por Douglas
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Add font awesome icons -->
</p>
</div>
</footer>
login.component.css:
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
background-color: black;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
color: lightgray;
}
.jumbotron{
margin-top: 0 auto;
background-color: black;
}
.form-signin .checkbox {
font-weight: 400;
color: lightgray;
}
.form-signin .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
background-color: white;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
background-color: white;
}
.btn-color {
color: black;
background-color: white;
}
.form-signin-heading{
text-align-last: center;
color: lightgray;
}
/* Style all font awesome icons */
.fa {
padding: 20px;
font-size: 30px;
width: 50px;
text-align: center;
text-decoration: none;
}
/* Add a hover effect if you want */
.fa:hover {
opacity: 0.7;
}
/* Facebook */
.fa-facebook {
background: #3B5998;
color: white;
}
/* Twitter */
.fa-twitter {
background: #55ACEE;
color: white;
}
.fa-instagram {
background: rgb(216, 128, 182);
color: white;
}
.footer{
margin-top: 0;
background:black;
}
the end result would look like this:
Try this.
style.scss
.bck-img {
background-image: url(./assets/images/your_image.jpg);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-repeat: no-repeat;
background-size: cover;
}
login.component.ts
ngOnInit(): void {
const body = document.getElementsByTagName('body')[0];
body.classList.add('bck-img');
}
...
ngOnDestroy(): void {
const body = document.getElementsByTagName('body')[0];
body.classList.remove('bck-img');
}
Make sure implement both OnInit& OnDestroylike this,
export class LoginComponent implements OnInit, OnDestroy { ... }
If you want also remove black part try this.
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
background-color: transparent;
}
Janitha Rasanga answer was right so i made the following change:
background-image: url(./assets/images/backgroundlogin.jpg);
for
background-image: url(/assets/images/backgroundlogin.jpg);

styled checkbox does not show check - with another class

I have an Issue that I tried to set a styled checkbox with a new class, so that this checkbox appears with a different layout than the "original" styled one.
The original looks like this:
<label for="bauherr_check">Bauherr</label>
<input id="bauherr_check" name="zielgruppen_check[]" value="bauherr_check" type="checkbox">
<label class="checkbox" for="bauherr_check">
::before
</label>
The CSS for the "original" code:
input[type=checkbox] {
display:none;
}
.checkbox:before {
content: "";
width: 12px;
height: 12px;
display: flex;
align-items: center;
background-color: #ffffff;
border-top: 1px solid #AAAAAA;
border-left: 1px solid #AAAAAA;
border-radius: 1px;
}
input[type=checkbox]:checked + .checkbox:before {
content: "\2713";
color:black;
font-size: 11pt;
}
The new one has the following code
<label class="label_details" for="sichtbar_check">Sichtbar?</label>
<input class="togglerIn" id="sichtbar_check" name="sockel_check[]" value="sichtbar_check" type="checkbox">
<label class="checkbox_details" for="sichtbar_check">
::before
</label>
The CSS of the new Box:
.checkbox_details:before {
content: "";
width: 12px;
height: 12px;
display: flex;
align-items: center;
background-color: #ffffff;
border-top: 1px solid #AAAAAA;
border-left: 1px solid #AAAAAA;
border-radius: 1px;
margin-left:-5px;
}
input[type=checkbox].check_details:checked + .checkbox_details:before {
content: "\2713";
color:black;
font-size: 11pt;
}
How comes that the second box does not show the check symbol (content) as soon as I check the box? Maybe someone can help? Thanks a lot.
I have found the solution myself... pretty quick though....
I just added a new class to the input field:
<input class="togglerIn" id="sichtbar_check" name="sockel_check[]" value="sichtbar_check" type="checkbox">
And styled the new class the same way than the "orignal" class:
input[type=checkbox]:checked + .checkbox:before, .check_details:checked + .checkbox_details:before {
content: "\2713";
color:black;
font-size: 11pt;
}
This way, the content appears as soon as I check the box.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.checkbox:checked:before {
transform: rotate(-45deg);
height: .5rem;
border-color: #009688;
border-top-style: none;
border-right-style: none;
}
.label-checkbox {
position: relative;
margin: .5rem;
font-family: Arial, sans-serif;
line-height: 135%;
cursor: pointer;
}
.checkbox {
margin: 0 1rem 0 0;
cursor: pointer;
}
.checkbox:before {
content: "";
position: absolute;
z-index: 1;
width: 1rem;
height: 1rem;
top: 0;
border: 2px solid green;
}
.checkbox:checked :before {
height: .5rem;
border-color: green;
border-top-style: none;
border-right-style: none;
}
.checkbox:after {
content: "";
position: absolute;
top: rem(-2);
left: 0;
width: 1.1rem;
height: 1.1rem;
background: #fff;
cursor: pointer;
}
</style>
</head>
<body>
<label class="label-checkbox">
<input type="checkbox" class="checkbox"> Item 4
</label>
</body>
</html>

Styling form checkboxes with font awesome, <input> inside of <label>

After following this question and getting the idea of styling which is shown below, I tried to replace the default checkboxes and style them.
Currently, the problem is that the checkboxes don't tick and I don't understand why.
Link to JsFiddle:
Fiddle Link Here
HTML
<div class="col-md-6 checkboxes">
<label for="id_tags_0"><input type="checkbox" name="tags" value="4" id="id_tags_0">
Tag 1</label>
<label for="id_tags_1"><input type="checkbox" name="tags" value="1" id="id_tags_1">
Tag 2</label>
</div>
CSS
.checkboxes label {
/*display: inline-block;*/
cursor: pointer;
position: relative;
}
/*Hide default checkbox*/
.checkboxes input[type=checkbox] { display: none; }
/*Show an empty box before the our label by default*/
.checkboxes label:before {
content: "";
display: inline-block;
margin-right: 10px;
position: absolute;
left: 0;
top: 3px;
background-color: #fff;
border: 2px solid #d0d0d0;
border-radius: 4px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
transition: all 0.25s;
font-family: "FontAwesome";
color: #fff;
text-align: center;
}
/*When checkbox input is checked, add a tick to our box */
.checkboxes label>input[type=checkbox]:checked:before {
/* Content: https://fontawesome.com/icons/check?style=solid */
content: "\f00c";
background-color: #66676b;
border: 2px solid #66676b;
}
.checkboxes label>input[type=checkbox]:checked {
/* Content: https://fontawesome.com/icons/check?style=solid */
content: "\f00c";
background-color: #66676b;
border: 2px solid #66676b;
}
You are trying to use parent selector, which is not possible through css.
Instead you can try this.
add a span after the checkbox and style it.
.checkboxes label {
/*display: inline-block;*/
cursor: pointer;
position: relative;
padding-left: 28px;
margin-right: 20px;
margin-bottom: 0;
line-height: 24px;
font-size: 16px;
}
/*Hide default checkbox*/
.checkboxes input[type=checkbox] { display: none; }
/*Show an empty box before the our label by default*/
.checkboxes label span:before {
content: "";
display: inline-block;
width: 19px;
height: 19px;
margin-right: 10px;
position: absolute;
left: 0;
top: 3px;
background-color: #fff;
border: 2px solid #d0d0d0;
border-radius: 4px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
transition: all 0.25s;
font-family: "FontAwesome";
font-size: 12px;
color: #fff;
text-align: center;
line-height: 15px;
}
/*When checkbox input is checked, add a tick to our box */
.checkboxes label>input[type=checkbox]:checked + span:before {
/* Content: https://fontawesome.com/icons/check?style=solid */
content: "\f00c";
background-color: #66676b;
border: 2px solid #66676b;
}
.checkboxes label>input[type=checkbox]:checked {
/* Content: https://fontawesome.com/icons/check?style=solid */
content: "\f00c";
background-color: #66676b;
border: 2px solid #66676b;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://use.fontawesome.com/releases/v5.0.9/css/all.css" rel="stylesheet"/>
<div class="col-md-6 checkboxes">
<label for="id_tags_0">
<input type="checkbox" name="tags" value="4" id="id_tags_0">
<span></span>
Tag 1</label>
<label for="id_tags_1"><input type="checkbox" name="tags" value="1" id="id_tags_1">
<span></span>
Tag 2</label>
<label for="id_tags_2"><input type="checkbox" name="tags" value="2" id="id_tags_2">
<span></span>
Tag 3</label>
<label for="id_tags_3"><input type="checkbox" name="tags" value="3" id="id_tags_3">
<span></span>
Tag 4</label>
<label for="id_tags_4"><input type="checkbox" name="tags" value="5" id="id_tags_4">
<span></span>
Tag 5</label>
</div>

focus pointer in center radio button with css3

I've customized this radio button and have trouble focusing the pointer inside the radio button .
<div class="radio">
<input id="left" type="radio" name="gender" value="left">
<label for="left">Left</label>
<input id="right" type="radio" name="gender" value="right">
<label for="right">Right</label>
</div>
label {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
margin-right: 15px;
}
input[type=radio] {
display: none;
}
label:before {
content: "";
display: inline-block;
width: 12px;
height: 12px;
margin-right: 10px;
position: absolute;
left: 0;
bottom: 1px;
background-color: #ffffff;
border: 3px solid;
border-color: #bababa;
}
.radio label:before {
border-radius: 8px;
}
input[type=radio]:checked + label:before {
content: "\2022";
color: #373c3e;
font-size: 60px;
text-align: center;
line-height: 16px;
}
Deputy example so that you can see the error.
Visit https://jsfiddle.net/drag/rbhzpvn3/1/
you can set just background color instead of > content: "\2022".
it means :
input[type=radio]:checked + label:before {
background-color: #373c3e;
}

CSS - child checkbox should ignore parent checkbox css

I have a common CSS for checkboxes in my application. But I want to get rid of this custom stylish CSS in few places. it should display as a default checkbox, not a customized one.
And i don't want to touch the parent CSS. since we are using a 3rd party framework for styling.
I’ve tried adding the id to 'not' selector in the parent CSS. it worked unfortunately i cannot modify it. I need a alternate approach. Please refer below jsfiddle.
HTML:
<input type="checkbox" href="#" class="menu-open" id="menu-open"/>
<label>Custom Css - ok</label>
<br/>
<input type="checkbox" href="#" class="menu-open" id="menu-open1"/>
<label>Custom Css - ok</label>
<br/>
...<br/>
...
<br/>
<h5>Below checkbox should display as default (without styling)</h5>
<input type="checkbox" href="#" class="menu-open" id="normal"/>
<label>It should be default</label>
CSS
input[type="checkbox"] {
-webkit-appearance: none;
height: 1.618em;
width: 1.618em;
cursor: pointer;
position: relative;
-webkit-transition: .15s;
border-radius: 2em;
background-color: #900;
margin-right: 1em;
margin-top: .53em;
}
input[type="checkbox"]:checked + label{
background-color: green;
}
input[type="checkbox"]:not(:checked) + label{
color: blue;
}
input[type="checkbox"]:before,
input[type="checkbox"]:checked:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
line-height: 2.818em;
text-align: center;
color: #fff;
content: "'";
font-family: 'WebSymbolsRegular';
font-size: .618em;
}
input[type="checkbox"]:checked:before {
content: '.';
}
input[type="checkbox"]:hover:before {
background: rgba(255, 255, 255, 0.3);
}
http://jsfiddle.net/vh2nothv/2/
Just use class in your css.
http://jsfiddle.net/pratyush141/age91svr/
<input type="checkbox" href="#" class="menu-open" id="menu-open"/>
<label>Custom Css - ok</label>
<br/>
<input type="checkbox" href="#" class="menu-open" id="menu-open1"/>
<label>Custom Css - ok</label>
<br/>
<input type="checkbox" href="#" class="menu-open1" id="menu-open1"/>
<label>Custom Css - ok</label>
<br/>
...<br/>
...
<br/>
CSS
.menu-open {
-webkit-appearance: none;
/* Hides the default checkbox style */
height: 1.618em;
width: 1.618em;
cursor: pointer;
position: relative;
-webkit-transition: .15s;
border-radius: 2em;
background-color: #900;
margin-right: 1em;
margin-top: .53em;
}
.menu-open:checked + label{
background-color: green;
}
.menu-open:not(:checked) + label{
color: blue;
}
.menu-open:before,
input[type="checkbox"]:checked:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
line-height: 2.818em;
text-align: center;
color: #fff;
content: "'";
font-family: 'WebSymbolsRegular';
font-size: .618em;
}
.menu-open:checked:before {
content: '.';
}
.menu-open:hover:before {
background: rgba(255, 255, 255, 0.3);
}

Resources