I need that when the focus is in the input, the label changes color, however, in my structure does not work. I'm using Bootstrap 4, Angular 5+ and my form is horizontal and vertical.
here is the html:
<form>
<div class="col-lg-12">
<div class="form-row">
<div class="col-12 col-xl-4 col-sm-12 col-md-4">
<label for="rg">Número do RG</label>
<div class="input-group">
<input [(ngModel)]="dados.rg" name="rg" id="rg" type="text" class="form-control"><span class="separator d-none d-md-block">-</span>
</div>
</div>
<div class="col-12 col-xl-4 col-sm-12 col-md-4">
<label for="data">Data de emissão</label>
<div class="input-group">
<input [textMask]="mask" id="data" [(ngModel)]="dados.data" name="data" type="text" class="form-control"><span class="separator d-none d-md-block">-</span>
</div>
</div>
<div class="col-12 col-xl-4 col-sm-12 col-md-4">
<label for="orgao">Orgão Expedidor</label>
<ng-select class="custom" [(ngModel)]="dados.orgaoExpedidor" id="orgao" name="orgao" (change)="onChange($event)">
<ng-option *ngFor="let orgao of orgaos" [value]="orgao.value">{{orgao.label}}</ng-option>
</ng-select>
</div>
</div>
</div>
<div class="col-lg-12 input-radio">
<div class="form-row form-inline justify-content-center">
<label class="radio-label">Sexo</label>
<div class="btn-group" btnRadioGroup [(ngModel)]="dados.sexo" name="radio">
<label class="btn btn-info" [value]="Masculino" btnRadio="Masculino" tabindex="0" name="masculino" role="button">Masculino</label>
<span class="separator">-</span>
<label class="btn btn-info" [value]="Feminino" btnRadio="Feminino" tabindex="0" name="feminino" role="button">Feminino</label>
</div>
</div>
</div>
</form>
in scss I do it like this:
input:focus {
border-color: $verde;
color: $verde;
}
I tried like this:
input:focus + label {
border-color: $verde;
color: $verde;
}
but it did not work, and the input lost its color
This is not working as the label is not directly placed after the input element. The + selector looks at direct decedents of the first selector, i.e. input + label targets all label elements IMMEDIATELY present after an input element.
In your case the span is the first element following the input.
A small structure change should do the trick.
The first input is structured to work:
<input [(ngModel)]="dados.rg" name="rg" id="rg" type="text" class="form-control">
<label for="rg"><span class="separator d-none d-md-block">-</span>Número do RG</label>
EDIT 1: The second input now uses the pseudo class focus-within. No support for this in IE/Edge yet. If this will not work. you can use the first case but style the label so it appears above. Also, you can use Javascript/JQuery to do this via code.
input:focus {
border-color: green;
color: green;
}
input:focus + label {
color: red;
}
.input-group:focus-within label {
color: red;
}
<form>
<div class="col-lg-12">
<div class="form-row">
<div class="col-12 col-xl-4 col-sm-12 col-md-4">
<div class="input-group">
<input [(ngModel)]="dados.rg" name="rg" id="rg" type="text" class="form-control">
<label for="rg"><span class="separator d-none d-md-block">-</span>Número do RG</label>
</div>
</div>
<div class="col-12 col-xl-4 col-sm-12 col-md-4">
<div class="input-group">
<label for="data">Data de emissão</label>
<input [textMask]="mask" id="data" [(ngModel)]="dados.data" name="data" type="text" class="form-control"><span class="separator d-none d-md-block">-</span>
</div>
</div>
<div class="col-12 col-xl-4 col-sm-12 col-md-4">
<label for="orgao">Orgão Expedidor</label>
<ng-select class="custom" [(ngModel)]="dados.orgaoExpedidor" id="orgao" name="orgao" (change)="onChange($event)">
<ng-option *ngFor="let orgao of orgaos" [value]="orgao.value">{{orgao.label}}</ng-option>
</ng-select>
</div>
</div>
</div>
<div class="col-lg-12 input-radio">
<div class="form-row form-inline justify-content-center">
<label class="radio-label">Sexo</label>
<div class="btn-group" btnRadioGroup [(ngModel)]="dados.sexo" name="radio">
<label class="btn btn-info" [value]="Masculino" btnRadio="Masculino" tabindex="0" name="masculino" role="button">Masculino</label>
<span class="separator">-</span>
<label class="btn btn-info" [value]="Feminino" btnRadio="Feminino" tabindex="0" name="feminino" role="button">Feminino</label>
</div>
</div>
</div>
</form>
try this in your css
.input-group {
input {
background-color: transparent;
&:focus {
border-color: $verde;
color: $verde;
}
}
}
Related
I have a list group in a card. When you hover over the topmost list group item, a border appears under it (no border when not hovering). When I set :hover override in Google Chrome's Dev Tools, the border doesn't appear. Why does this happen?
https://jsfiddle.net/williamqin123/0fkwsemn/
<div class="container">
<div class="shadow-sm card my-5">
<div class="list-group list-group-flush">
<div class="text-center list-group-item">
<h1 class="text-left d-inline-block mb-0">
Submit
<small class="text-muted">Create your ad in less than 1 minute</small>
</h1>
</div>
<form action="/submit" method="POST" class="mb-0">
<div class="form-group list-group-item">
<label for="site">Site</label>
<div class="input-group" id="site-menu">
<select class="form-control text-center" name="site" id="site" required>
</select>
<div class="btn-group-toggle input-group-append" data-toggle="buttons">
<label class="btn btn-outline-primary">
<input type="checkbox" name="meta" value='checked'> Meta
</label>
</div>
</div>
</div>
<div class="form-group list-group-item">
<label for="post-id">Post ID</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">#</span>
</div>
<input class="form-control text-center" type="number" min="1" step="1" name="id" id="post-id" required>
</div>
</div>
<div class="form-group text-center list-group-item">
<input class="btn btn-primary btn-lg" type="submit" value="Proceed">
</div>
</form>
</div>
</div>
</div>
There is a border on the element:
.list-group-item {
position: relative;
margin-bottom: -1px;
border: 1px solid rgba(0,0,0,.125);
}
You can't see it initially because the negative margin makes the next element shift upwards (by 1px) and overlap it.
This code...
.list-group-item:hover {
z-index: 1;
}
...adds a new stacking context, making it appear in front, and allows you to see the border.
I have a form group, it contains of an input field with an addon, a checkbox with an image and a button next to them, they're displayed next to each other, but when i give my checkbox height and width the image and the button move down i don't know why, how can i fix that? here is my code:
.box{
height: 34px;
width: 34px;
}
.btn-default{
height: 34px;
width: 34px;
}
<div class="col-lg-12 form-group">
<div class="pull-right">
<img src="http://placehold.it/34x34"><input type="checkbox" class="box">
<button type="button" class="btn btn-default">+</button>
</div>
<div>
<div class="input-group">
<span class="input-group-addon">#</span>
<input type="text" class="form-control"/>
</div>
</div>
</div>
You can use grid system to easily manage your layout
Please check below example
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<style>
input.checkbox-input{height: 34px;width: 34px;margin-top: 0;}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 form-group">
<div class="col-md-1 col-sm-1 col-xs-1">
<img src="http://placehold.it/34x34">
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<input type="checkbox" class="checkbox-input">
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<button class="btn" value="+">+</button>
</div>
<div class="col-md-9 col-xs-9 input-group">
<span class="input-group-addon">#</span>
<input type="text" class="form-control">
</div>
</div>
</div>
</div>
I want to select first input from this structure. I need only CSS selector, not jQuery.
<div class="sonata-ba-collapsed-fields">
<div class="form-group" id="sonata-ba-field-container-s55e92cd5ce823_logoFile">
<label class=" control-label">Logo File</label>
<div class=" sonata-ba-field sonata-ba-field-standard-natural ">
<div class="vich-image">
<div class="form-group ">
<label class=" control-label" for="s55e92cd5ce823_logoFile_file">Logo File</label>
<div class="">
<input type="file" id="s55e92cd5ce823_logoFile_file" name="s55e92cd5ce823[logoFile][file]" class=" form-control">
</div>
</div>
</div>
</div>
</div>
<div class="form-group" id="sonata-ba-field-container-s55e92cd5ce823_iconFile">
<label class=" control-label">Icon File</label>
<div class=" sonata-ba-field sonata-ba-field-standard-natural ">
<div class="vich-image">
<div class="form-group ">
<label class=" control-label" for="s55e92cd5ce823_iconFile_file">Icon File </label>
<div class="">
<input type="file" id="s55e92cd5ce823_iconFile_file" name="s55e92cd5ce823[iconFile][file]" class=" form-control">
</div>
</div>
</div>
</div>
</div>
</div>
I'm doing something like this http://jsfiddle.net/T4kAq/60/ but as you can see it selects both.
CSS selector can be like this:
div.sonata-ba-collapsed-fields > .form-group:nth-child(1) input {
background-color: #ff0000;
}
Demo: http://jsfiddle.net/T4kAq/61/
div.sonata-ba-collapsed-fields > .form-group:first-child input:nth-child(1) {
background-color: #ff0000;
}
Jsfiddle Demo
I need to have a input or a textarea inside a label and be displayed inline in my form which is styled using Bootstrap 3. The following code is just a sample and my original code is different and more complex. I want to make sure that they look consistent with the remaining elements in the form.
Bootply
I want the label, input and textarea to look consistent with the Bootstrap form styling and have tried adding control-label and form-control classes to get the bootstrap styling but it doesn't work.
How to make the input answer1 and textarea answer2 have the Bootstrap styling like the Name and Id in the same form and also be inline with the labels surrounding them?
Code
HTML
<form class="form-horizontal padding-md" id="form1">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<label class="control-label col-xs-5 col-sm-4 col-md-3" for="sName">Name</label>
<div class="controls col-xs-7 col-sm-8 col-md-9"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Name of the student."></span>
<input type="text" id="sName" name="Name" class="form-control" placeholder="Enter Name">
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<label class="control-label col-xs-4 col-sm-3 col-md-3" for="sId">Id</label>
<div class="controls col-xs-8 col-sm-9 col-md-9"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Id of the student."></span>
<input type="text" id="sId" name="Id" class="form-control" placeholder="Enter Id">
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label class="control-label col-xs-3 col-sm-2 col-md-1" for="answer1">1.</label>
<div class="controls col-xs-9 col-sm-10 col-md-11"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Answer for first question."></span>
<div class="inline">[<div class="sname">Student</div>'s answer: "<input type="text" id="answer1" name="Answer1" placeholder="Enter Answer">"]</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label class="control-label col-xs-3 col-sm-2 col-md-1" for="answer2">2.</label>
<div class="controls col-xs-9 col-sm-10 col-md-11"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Answer for second question."></span>
<div class="inline">[<div class="sname">Student</div>'s answer: "<textarea id="answer2" name="Answer2" placeholder="Enter Answer"></textarea>"]</div>
</div>
</div>
</div>
<div class="row pull-right">
<button type="submit" class="btn btn-primary" id="submitAnswers">Submit Answers</button>
</div>
</form>
JavaScript
$('#sName').on('input', function() {
$('.sname').html($('#sName').val()?$('#sName').val():"Student");
});
CSS
.help {
position:absolute;
right:-5px;
top:8px;
}
.inline {
display:inline-block;
width:100%;
}
.sname {
display:inline;
}
.padding-md {
padding: 25px;
}
With help from Rachel and after some reading about display:table I have found a solution by using display:table and display:table-cell. This solution is very close to what I want except that I don't want the width of sname1 and sname2 to be a fixed value. It should ideally be adjusting based on the width of the name entered in sName. I will be using this solution till someone posts a better solution.
Solution:
JSFiddle
$('#sName').on('input', function () {
$('.sname').html($('#sName').val() ? $('#sName').val() : "Student");
});
.help {
position:absolute;
right:-5px;
top:8px;
}
.inline {
display:table;
font-weight:bold;
width:100%;
}
.sname2, .tail2 {
vertical-align:top;
}
.sname {
display:inline;
}
.sname1, .sname2 {
width:150px;
font-weight:bold;
display:table-cell;
}
.padding-md {
padding: 25px;
}
.inline > .form-control {
width:100%;
display:table-cell;
}
.tail1, .tail2 {
padding-left:10px;
width: 30px;
display:table-cell;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<form class="form-horizontal padding-md" id="form1">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<label class="control-label col-xs-5 col-sm-4 col-md-3" for="sName">Name</label>
<div class="controls col-xs-7 col-sm-8 col-md-9"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Name of the student."></span>
<input type="text" id="sName" name="Name" class="form-control" placeholder="Enter Name" />
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<label class="control-label col-xs-4 col-sm-3 col-md-3" for="sId">Id</label>
<div class="controls col-xs-8 col-sm-9 col-md-9"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Id of the student."></span>
<input type="text" id="sId" name="Id" class="form-control" placeholder="Enter Id" />
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label class="control-label col-xs-1 col-sm-1 col-md-1" for="answer1">1.</label>
<div class="controls col-xs-11 col-sm-11 col-md-11"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Answer for first question."></span>
<div class="inline">
<div class="sname1">[<div class="sname">Student</div>'s answer: "</div>
<input type="text" id="answer1" class="form-control" name="Answer1" placeholder="Enter Answer" />
<div class="tail1">" ]</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label class="control-label col-xs-1 col-sm-1 col-md-1" for="answer2">2.</label>
<div class="controls col-xs-11 col-sm-11 col-md-11"> <span class="help glyphicon glyphicon-info-sign" data-toggle="popover" data-placement="right" title="Answer for second question."></span>
<div class="inline">
<div class="sname2">[<div class="sname">Student</div>'s answer: "</div>
<textarea id="answer2" class="form-control" name="Answer2" placeholder="Enter Answer"></textarea>
<div class="tail2">" ]</div>
</div>
</div>
</div>
</div>
<div class="row pull-right">
<button type="submit" class="btn btn-primary" id="submitAnswers">Submit Answers</button>
</div>
</form>
After searching everywhere i couldnt see exactly how i can design an inline form that has the following design: (using bootstrap 3 classes instead of css customizations when possible)
When the user has a wide screen:
Form-Legend
LabelFieldA: InputFieldA LabelFieldB: InputFieldB LabelFieldC: InputFieldC <Submit Button>
When the user has a smaller screen:
Form-Legend
LabelFieldA: InputFieldA LabelFieldB: InputFieldB
LabelFieldC: InputFieldC <Submit Button>
The idea is that the design initially puts all the fields in one line and if it doesnt fit the controls would jump to the next line, but maintaining the Label + Field together.
Also if there is a way so the spacing between each Label + Input is greater than the spacing between the Label and its Field.
And lastly if there is a way of having more vertical margin between the Label + Field when it jumps to the next line.
Option #1 : fixed columns
You can use a structure mixing col-xs-12, col-sm-6 and col-lg-3 to get 1, 2 or 4 columns. Inside your form-group, remember to fix label/input sizes with col-xs-4 and col-xs-8 :
<div class="container">
<form class="form form-inline" role="form">
<legend>Form legend</legend>
<div class="form-group col-xs-12 col-sm-6 col-lg-3">
<label for="InputFieldA" class="col-xs-4">Field A</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="InputFieldA" placeholder="InputFieldA">
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-3">
<label for="InputFieldB" class="col-xs-4">Field B</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="InputFieldB" placeholder="InputFieldB">
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-3">
<label for="InputFieldC" class="col-xs-4">Field C</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="InputFieldC" placeholder="InputFieldC">
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-3">
<button type="submit" class="btn btn-default col-xs-8 col-xs-offset-4">Submit Button</button>
</div>
</form>
</div>
You still need a few CSS :
// get a larger input, and align it with submit button
.form-inline .form-group > div.col-xs-8 {
padding-left: 0;
padding-right: 0;
}
// vertical align label
.form-inline label {
line-height: 34px;
}
// force inline control to fit container width
// http://getbootstrap.com/css/#forms-inline
.form-inline .form-control {
width: 100%;
}
// Reset margin-bottom for our multiline form
#media (min-width: 768px) {
.form-inline .form-group {
margin-bottom: 15px;
}
}
You can add as many inputs as you want.
Bootply
Option #2 : fluid columns
To be able to not care of the number of fields per row, you can use this structure :
<div class="container">
<form class="form form-inline form-multiline" role="form">
<legend>Form legend</legend>
<div class="form-group">
<label for="InputFieldA">Field A</label>
<input type="text" class="form-control" id="InputFieldA" placeholder="InputFieldA">
</div>
<div class="form-group">
<label for="InputFieldB">Very Long Label For Field B</label>
<input type="text" class="form-control" id="InputFieldB" placeholder="InputFieldB">
</div>
<div class="form-group">
<label for="InputFieldC">F. C</label>
<input type="text" class="form-control" id="InputFieldC" placeholder="InputFieldC">
</div>
<div class="form-group">
<label for="InputFieldD">Very Long Label For Field D</label>
<input type="text" class="form-control" id="InputFieldD" placeholder="InputFieldD">
</div>
<div class="form-group">
<label for="InputFieldE">Very Long Label For Field E</label>
<input type="text" class="form-control" id="InputFieldE" placeholder="InputFieldE">
</div>
<div class="form-group">
<label for="InputFieldF">Field F</label>
<input type="text" class="form-control" id="InputFieldF" placeholder="InputFieldF">
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Submit Button</button>
</div>
</form>
</div>
And a few CSS lines to fix margins :
.form-multiline .form-group {
margin-bottom: 15px;
margin-right: 30px;
}
.form-multiline label,
.form-multiline .form-control {
margin-right: 15px;
}
Bootply
The same as option #1 from #zessx, but without overriding CSS. This one also aligns labels to the right to increase space between label-control pairs. Class "media" is there to add top margin without creating a custom class, but in general case it is better to have a custom one.
<div class="form-horizontal">
<legend>Form legend</legend>
<div class="media col-xs-12 col-sm-6 col-lg-3">
<label for="InputFieldA" class="control-label text-right col-xs-4">Field A</label>
<div class="input-group col-xs-8">
<input type="text" class="form-control" id="InputFieldA" placeholder="InputFieldA">
</div>
</div>
<div class="media col-xs-12 col-sm-6 col-lg-3">
<label for="InputFieldB" class="control-label text-right col-xs-4">Field B</label>
<div class="input-group col-xs-8">
<input type="text" class="form-control" id="InputFieldB" placeholder="InputFieldB">
</div>
</div>
<div class="media col-xs-12 col-sm-6 col-lg-3">
<label for="InputFieldC" class="control-label text-right col-xs-4">Field C</label>
<div class="input-group col-xs-8">
<input type="text" class="form-control" id="InputFieldC" placeholder="InputFieldC">
</div>
</div>
<div class="media col-xs-12 col-sm-6 col-lg-3">
<button type="submit" class="btn btn-default col-xs-8 col-xs-offset-4">Submit Button</button>
</div>
</div>
Bootply
I would propose something completely different, wrap the labels and fields inside inline divs:
<div style="display:inline-block">
Label:input
</div>
This way, when they are about to break, they break in pairs, labels+inputs.
Alright I played with the grid system and this is as close as I could get to your setup.
<div class="container">
<form role="form" class="form-horizontal">
<div class="form-group col-sm-5">
<label for="inputPassword" class="col-xs-4 control-label">Email</label>
<div class="col-xs-8">
<input type="password" class="form-control" id="inputPassword" placeholder="Password" />
</div>
</div>
<div class="form-group col-sm-5">
<label for="inputPassword" class="col-xs-4 control-label">Password</label>
<div class="col-xs-8">
<input type="password" class="form-control" id="inputPassword" placeholder="Password" />
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
This has two fields only. You might want to change the col classes to fit your layout.
jsFiddle
You can try below
Working here- http://www.bootply.com/117807
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="row">
<div class="col-md-4 col-xs-3 col-sm-4"><label>First Name</label></div>
<div class="col-md-8 col-xs-9 col-sm-8"><input type="text"></div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-4 col-xs-3 col-sm-4"><label>Last Name</label></div>
<div class="col-md-8 col-xs-9 col-sm-8"><input type="text"></div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-4 col-xs-3 col-sm-4"><label>Contact</label></div>
<div class="col-md-8 col-xs-9 col-sm-8"><input type="text"></div>
</div>
</div>
</div>
</div>
The simplest way is to put both label and text input in cols div. Hope this will save time for all others :)
<div class="col-md-3 text-right">
<label>City</label>
</div>
<div class="col-md-3 text-right">
<asp:TextBox data-toggle="tooltip" pbpo-validation-type="required" title="City" runat="server" ID="textbox_city" CssClass="form-control input-sm" ClientIDMode="Static" placeholder=""></asp:TextBox>
</div>