Highlight the label item after clicking on checkbox - html

I am trying to display the cards as input type is a checkbox, on selecting the cards I am able to fetch the details what are cards selected by the user, and my requirement is I required to highlight the card which is selected by the user.
for example, I need to highlight the card whose checkbox is checked, and if the checkbox is unchecked I need to show as the card.
lable+input[type=checkbox]:checked {
//some css code
}
<form [fromGropu]="form1">
<label for="{{i}}" *ngFor="let item of items" ;let i=index ">
<input type="checkbox " id="{{i}} " [value]="item " (change)="onchange() "/>
<div class="card rounded-0 ">
<div class="card-header ">{{item.header}}</div>
<diva class="card-body>{{item.desc}}</div>
<div class="card-footer">{{item.footer}}</div>
</div>
</div>
</label
</form>
but above CSS is not working, could anyone help on this

After input checked, the div.card following input should apply the css.
Your css should be like this
input[type=checkbox]:checked + div.card{
color: red;
}
Demo https://stackblitz.com/edit/angular-checked-input?file=src/app/app.component.css

Why not just highlight using a class which is toggled using ngClass? please try this change.
<form>
<label for="{{i}}" *ngFor="let item of items;let i =index" (click)="item.active = !item.active;"
[ngClass]="item.active ? 'active' : ''" style="display:block;">
<div class="card rounded-0">
<div class="card-header">{{item.header}}</div>
<div class="card-body">{{item.desc}}</div>
<div class="card-footer">{{item.footer}}</div>
</div>
</label>
</form>
Note: please delete this active property for the array used if you are sending the data to any API. Below is a working example!
Stack Blitz Demo

.services input[type="checkbox"] {
display: none;
}
.services label {
height: 100%;
padding: 10px;
margin: 0px;
border-radius: 0.55rem;
}
.services input[type="checkbox"]:checked + label {
background: #20df80;
}
.services input[type="checkbox"]:checked + label::after {
font-family: "Font Awesome 5 Free";
font-weight: 900;
border: 2px solid #1dc973;
content: "\f00c";
font-size: 24px;
position: absolute;
top: -25px;
left: 50%;
transform: translateX(-50%);
height: 50px;
width: 50px;
line-height: 50px;
text-align: center;
border-radius: 50%;
background: white;
}
.services img{
max-width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class='container mt-5'>
<div class="row services">
<div class="col-4 col-sm-4 col-md-3 col-lg-3 mb-5 d-flex justify-content-star">
<div class="card shadow-soft text-center" style="width: 100%;">
<input class="" type="checkbox" id="24 Horas" name="type[]" value="5" checked>
<label for="24 Horas">
<br>
<h5 class="card-title"><strong>24 Horas</strong></h5>
<img src="https://icon-library.com/images/icon-img/icon-img-29.jpg" alt="">
</label>
</div>
</div>
<div class="col-4 col-sm-4 col-md-3 col-lg-3 mb-5 d-flex justify-content-star">
<div class="card shadow-soft text-center" style="width: 100%;">
<input class="" type="checkbox" id="Aire acondicionado" name="type[]" value="4">
<label for="Aire acondicionado">
<br>
<h5 class="card-title"><strong>Aire acondicionado</strong></h5>
<img src="https://icon-library.com/images/icon-img/icon-img-29.jpg" alt="">
</label>
</div>
</div>
<div class="col-4 col-sm-4 col-md-3 col-lg-3 mb-5 d-flex justify-content-star">
<div class="card shadow-soft text-center" style="width: 100%;">
<input class="" type="checkbox" id="Bar" name="type[]" value="8">
<label for="Bar">
<br>
<h5 class="card-title"><strong>Bar</strong></h5>
<img src="https://icon-library.com/images/icon-img/icon-img-29.jpg" alt="">
</label>
</div>
</div>
<div class="col-4 col-sm-4 col-md-3 col-lg-3 mb-5 d-flex justify-content-star">
<div class="card shadow-soft text-center" style="width: 100%;">
<input class="" type="checkbox" id="Buffet" name="type[]" value="3" checked>
<label for="Buffet">
<br>
<h5 class="card-title"><strong>Buffet</strong></h5>
<img src="https://icon-library.com/images/icon-img/icon-img-29.jpg" alt="">
</label>
</div>
</div>
</div>
</div>

Related

Custom FileInput on card - Bootstrap 5

I am trying to add a custom file selection on the card using Bootstrap:
I try this:
<style>
label {
cursor: pointer;
}
.custom-input-image {
opacity: 0;
position: absolute;
z-index: -1;
}
</style>
<div class="row mb-2">
<div class="col-md-4 text-center">
<input type="file" id="id_img_1" name="id_img_1" class="custom-input-image">
<label for="id_img_1" class="hover-shadow-lg hover-translate-y-n3">
<div class="card">
<div class="card-body text-center">
<!-- Image content-->
<div>
<div>
<h4 class="mb-1"><i class="camera-icon"></i></h4>
<small>Select file...</small>
</div>
</div>
</div>
</div>
</label>
</div>
[...more cards..]
</div>
It gets the following effect:
I need this:
Adding a label to a card causes the card to shrink. How to get full length of card with added file selection.
I've used font-awesome icons just as a placeholder icon, but you can try something like this:
label {
cursor: pointer;
display: block;
font-size: 0.875rem;
margin-top: 10px;
}
.custom-input-image {
opacity: 0;
position: absolute;
z-index: -1;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
<div class="col-md-12 col-sm-12">
<div class="row g-2 mt-3">
<div class="col-md-4 col-sm-4 text-center">
<input type="file" name="" id="" class="custom-input-image">
<div class="card p-4 border border-3">
<i class="fas fa-camera fa-2x"></i>
<label for="">Select file</label>
</div>
</div>
<div class="col-md-4 col-sm-4 text-center">
<input type="file" name="" id="" class="custom-input-image">
<div class="card p-4 border border-3">
<i class="fas fa-camera fa-2x"></i>
<label for="">Select file</label>
</div>
</div>
<div class="col-md-4 col-sm-4 text-center">
<input type="file" name="" id="" class="custom-input-image">
<div class="card p-4 border border-3">
<i class="fas fa-camera fa-2x"></i>
<label for="">Select file</label>
</div>
</div>
</div>
</div>

I want to make the height of this section increase with its content

I tried this
<section class="unique">
<div class="this d-flex pt-5">
<div class="leftside2 w-50 h-100">
<img src="images/twowomen.jpg" alt="twowomen" class="img-fluid">
</div>
<div class="rightside2 w-50 h-100">
<h5 class="text-success pl-5">WE HELP YOU</h5>
<div class="fineText d-flex pl-5">
<h3>Get A</h3>
<h3 class="consulting pl-2">CONSULTING</h3>
</div>
<form action="">
<div class="form-group">
<input type="text" class="inputs font-weight-bold py-2 ml-5" placeholder="Your Name" id="fname" required>
</div>
<div class="form-group">
<input type="text" class="inputs font-weight-bold py-2 ml-5" placeholder="Your Email Adress" id="fname" required>
</div>
<div class="form-group">
<input type="text" class="inputs font-weight-bold py-2 ml-5" placeholder="Phone Number" id="fname" required>
</div>
<div class="form-group">
<input type="text" class="inputs font-weight-bold py-2 ml-5" placeholder="I would like to discuss" id="fname" required>
</div>
<div class="form-group">
<button type="button" class="btn btn-success ml-5">SUBMIT</button>
</div>
</form>
</div>
</div>
<div class="info bg-success w-25 text-white font-weight-bold p-4">
<span>ADDRESS</span>
<p class="pb-3">Mostafa Naguib <br> Street, 14 Box, Cairo, <br> Egypt</p>
<span>EMAIL</span>
<p class="pb-3">cairooffice#financer.com</p>
<span>PHONE NUMBER</span>
<p class="pb-3">002 0100 843 1112</p>
<span>WEBSITE</span>
<p>www.financer.org</p>
</div>
</section>
Then the style:
.form-group .inputs{
border: none !important;
border-bottom: 1px solid #ccc !important;
width: 70% !important;
}
.form-group .btn{
padding: 15px !important;
padding-left: 45px !important;
padding-right: 45px !important;
border-radius: 50px !important;
}
.fineText .consulting{
font-size: 37px;
font-family: "Gabriola";
color: #28a745;
font-weight: bolder;
}
.rightside2{
padding-left: 100px !important;
}
.info{
position: absolute;
top: 1630px;
left: 400px;
/* padding: 35px !important; */
}
.unique{
height: 600px;
}
.this .rightside2 .leftside2{
height: 100%;
}
But after trying it only the section's height increases but the leftside and rightside`
remains the same.
See this image:
The space above and below the image is the height of the section and those leftside and rightside is supposed to fill the space.
I've made research i didn't find any helpful suggestion.
Please I need help. Thanks in advance
Instead of using fixed measurements, why don't you try using percentages? I am also not clear on what you mean by
The space above and below the image is the height of the section and those leftside and rightside is supposed to fill the space.
Could you expand on that and maybe I can help further?

Add div image over a form div

I have this basic form
<div class="card mb-5 card-central-responsive" style="min-height: 579px;">
<div class="card-body">
<form #apkCreationForm="ngForm" class="mt-2" novalidate (ngSubmit)="onSubmitApk()">
<div role="alert" class="mb-& ng-star-inserted" style="padding-bottom: .10rem" ng-reflect-ng-class="">
<h4 class="alert-heading">{{ 'apk.product-description' | translate }}</h4>
</div>
<div class="row">
<div class="col-6">
<label class="form-group has-float-label">
<input class="form-control" required ngModel #name="ngModel" name="name" [(ngModel)]="apkName"/>
<span>{{ 'apk.name' | translate }}</span>
<div *ngIf="!name.valid && apkCreationForm.submitted" class="invalid-tooltip">{{ 'apk.name-required' | translate }}!</div>
</label>
</div>
<div class="col-6">
<label class="form-group has-float-label">
<ng-select
[items]="isFree"
bindLabel="id"
name="isFree"
bindValue="id"
[(ngModel)]="isFreeSelected">
</ng-select>
<span>{{ 'apk.is-free' | translate }}</span>
<div *ngIf="!isFreeSelected && apkCreationForm.submitted" class="invalid-tooltip">{{ 'apk.isfree-required' | translate }}</div>
</label>
</div>
</div>
</div>
</form >
</div>
</div>
I have to add a div image on top of this form to have something like this:
I tried many solutions without success. Please how could I achieve this ?
I use ng-bootstrap in my app
Thanks in advance
By applying Position absolute, you can align any object. I just wanted to show you the procedure you're going to do in a simple way.
body {
background-color: #121723;
}
.container {
margin-top: 200px;
}
.form-container {
background-color: #252A39;
color: #f1f1f1;
height: 30rem;
position: relative;
padding-top: 40px;
}
.image-container {
position: absolute;
top: -30%;
left: 5%;
width: 15rem;
height: 15rem;
background-color: #2E3446;
padding: 15px;
border-radius: 3px;
}
.bordered-div {
width: 100%;
height: 100%;
border: 3px dashed #121723;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container">
<div class="form-container">
<!-- image-container -->
<div class="image-container">
<div class="bordered-div">
</div>
</div>
<!-- image-container end -->
<div class="row no-gutters form-tab">
<div class="col-md-2 offset-md-3">
<h6 class="text-capitalize text-right">product details</h6>
</div>
<div class="col-md-2">
<h6 class="text-capitalize text-right">graphic assets</h6>
</div>
<div class="col-md-2">
<h6 class="text-capitalize text-right">categorization</h6>
</div>
</div>
<div class="form-input">
<!-- İnputs -->
</div>
</div>
</div>
You could use about div's in css
position: absolute;
left: %10;
top: %10;
But when on the different pixels measurement, you should something css diversity.

How to show multiple radioButtons in two columns

I am showing radio buttons dynamically in two columns. As you can see in picture
It looks fine in few conditions but sometimes when text is large it looks off. How can I resolve this issue
Here is some code:
.radiobox-padding-top{
padding-top:15px;
}
input[type=radio] {
float: left;
display: block;
margin-top: 4px;
}
label {
margin-left: 15px;
display: block;
}
here is html code (I am using angular)
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 col-xl-8 remove-padding question-row-face">
<div class="col-12" >
<p class="grey-text inlineBlock question-padding">{{data.help_text}}</p>
</div>
<div class="row" style="margin: 0px">
<div class="col-12 radiobox-padding-top">
<div class="form-group">
<span *ngFor="let entry of options; index as i">
<div class="col-5 inlineBlock">
<div class="radio">
<input type="radio" name="{{data.slug}}" checked value="{{options[i]}}">
<label>
{{options[i]}}
</label>
</div>
</div>
</span>
</div>
</div>
</div>
</div>
I have created a running stackblitz.
Modify your code like this:
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 col-xl-8 remove-padding question-row-face">
<div class="col-12" >
<p class="grey-text inlineBlock question-padding">{{data.help_text}}</p>
</div>
<div class="row" style="margin: 0px">
<div class="col-12 radiobox-padding-top">
<div class="form-group">
<div class="row">
<div class="col-6" *ngFor="let entry of options; index as i">
<div class="inlineBlock">
<div class="radio">
<input type="radio" name="{{data.slug}}" checked value="{{options[i]}}">
<label>
{{options[i]}}
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Additionally change your CSS like this:
.radiobox-padding-top{
padding-top:15px;
}
input[type=radio] {
float: left;
margin-top: 4px;
}
label {
padding-left: 5px;
margin-left: 15px;
display: block;
}
For more informations about bootstrap breakpoints have a look here.

bootstrap placeholder not working on a input type

I have a HTML which has a div with multiple inputs(with placeholder). For some reason the placeholder is not displayed properly.Also, need the 2 input button(text) to be placed next to each other.
Here is the jsfiddle.
http://jsfiddle.net/o2qt6910/
HTML
<div class="container">
<div class="row row-bordered voffset4">
<div class="col-md-12">
<label class="radio-inline"><input type="radio" name="optradio">Aisles</label>
<label class="radio-inline"><input type="radio" name="optradio">Poses</label>
<label class="radio-inline"><input type="radio" name="optradio">Exclusion Zones</label>
</div>
</div>
<div class="row row-bordered">
<div class="col-md-4">
<button type="button" class="btn" id="add-aisle">Add</button>
<div id="aisle-coordinate-container">
<div class="col-md-1"> <input type="text" class="form-control" id="inputKey" placeholder="X"> </div>
<div class="col-md-1"> <input type="text" class="form-control" id="inputValue" placeholder="Value"> </div>
</div>
</div>
<div class="col-md-8">
<canvas id="myCanvas"></canvas>
</div>
</div>
<!--<div class="row">-->
<!--<img src="/static/images/lena.png" alt="Italian Trulli">-->
<!--</div>-->
</div>
CSS
#import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css";
.row-bordered:after {
content: "";
display: block;
border-bottom: 5px solid #ccc;
margin: 0 25px;
}
.voffset { margin-top: 2px; }
.voffset1 { margin-top: 5px; }
.voffset2 { margin-top: 10px; }
.voffset3 { margin-top: 15px; }
.voffset4 { margin-top: 30px; }
.voffset5 { margin-top: 40px; }
.voffset6 { margin-top: 60px; }
.voffset7 { margin-top: 80px; }
.voffset8 { margin-top: 100px; }
.voffset9 { margin-top: 150px; }
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
Try this:
<div class="row row-bordered">
<div class="col-md-4">
<div class="col-xs-12">
<button type="button" class="btn col-xs-2" id="add-aisle">Add</button>
</div>
<div id="aisle-coordinate-container">
<div class="col-sm-6">
<input type="text" class="form-control" id="inputKey" placeholder="X">
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputValue" placeholder="Value">
</div>
</div>
</div>
<div class="col-md-8">
<canvas id="myCanvas"></canvas>
</div>
</div>
There is some issue in Fiddle in alignments. I've tested this in my browser, input elements are now in one line with placeholders visible properly.
<div class="row row-bordered">
<div class="col-md-4">
<button type="button" class="btn" id="add-aisle">Add</button>
</div>
</div>
<div class="row">
<div id="coordinate-container">
<div class="col-md-3 col-sm-3"> <input type="text" class="form-control" id="inputKey" placeholder="X"> </div>
<div class="col-md-3 col-sm-3"> <input type="text" class="form-control" id="inputValue" placeholder="Value"> </div>
</div>
</div>
<div class="col-md-8">
<canvas id="myCanvas"></canvas>
</div>
</div>
Is this how you want it to be? I'm having a hard time visualising what is it that you want.
Do you want the add button and the inputs on the same line or next?
Edit: Changed the button to be on another row. There is no need for it to be on the same row, if you want it on another line.
Its not an issue with the code but more how you are using the bootstrap grid. Your parent container has col-md-4 but the div with the input boxes have col-md-1 which only 1/4th of the width to be shown so its squished down. If you remove the col-md-1 classes it shows up correctly.
Quick suggestion: If you want to use a col-md-x class you can add row class to the <div id="coordinate-container">