Border appears on hover - html

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.

Related

Change label color when input is focus

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;
}
}
}

Bootstrap forms aligning. "form-group row" misplaced

I'm having this problem, next "form-group row" misplaced. Working on django/jinja template (flask project).
This code:
<div class="row">
<div style="color: chocolate; padding: 10px; margin-left: 10px; font-size: 25px;">Client Details</div>
<div class="col-md-12" style="padding: 20px 0px 0px;">
<form class="form-horizontal">
<div class="col-md-6" style="border-left: 5px solid #eee; margin: 0 0 20px;">
<div class="form-group row">
<label id="labelbox" class="col-sm-2 col-form-label">Client ID</label>
<div class="input-group col-sm-6">
<input class="form-control" col-sm-6 type="text" value="" id="client-id" readonly>
<span class="input-group-btn">
<button class="btn" type="button" data-clipboard-target="client-id">Copy</button>
</span
</div>
</div>
<div class="form-group row">
<label id="labelbox" class="col-sm-2 col-form-label">Client Secret</label>
<div class="input-group col-sm-10">
<input class="form-control" type="text" value="" id="client-secret" readonly>
<span class="input-group-btn">
<button class="btn" type="button" data-clipboard-target="client-secret">Copy</button>
</span
</div>
</div>
</div>
</form>
</div>
This behavior is here: http://www.bootply.com/Ig0ilwpSdh
Ideally I would like to have newline, which I could do with , but since I'm using bootstrap, I'm thinking everything could be done with just bootstrap.
And also vertically align input fields.
By the way, misplacing appears, when I add:
<span class="input-group-btn">
Can you advice how I should better handle that?

How to maintain the width after adding icon next to dropdown list

Based on my code, is there any way to make the dropdown list align with the other input fields?
I need to add an icon right next to the dropdown list. However, class="form-control" should be 100% width by default but it doesn't after I added the icon.
<form asp-action="Apply" asp-controller="Jobs">
<div class="form-horizontal">
<div class="form-group">
<label asp-for="Name" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Name" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="YearsAttended" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="YearsAttended" class="form-control" min="0" value="0"/>
</div>
</div>
<div class="form-group">
<label asp-for="HighestQualification" class="col-md-2 control-label"></label>
<div class="col-md-10 form-inline">
<select asp-for="HighestQualification" asp-items="Html.GetEnumSelectList<QualificationLevel>()" class="form-control">
<option value="">Choose one...</option>
</select>
help</i>
</div>
</div>
</div>
</form>
You're probably best making use of Input Groups provided by bootstrap.
HTML
<div class="form-group">
<label asp-for="HighestQualification" class="col-md-2 control-label"></label>
<div class="col-md-10">
<div class="form-inline input-group">
<select asp-for="HighestQualification" asp-items="Html.GetEnumSelectList<QualificationLevel>()" class="form-control">
<option value="">Choose one...</option>
</select>
<span class="input-group-addon">
<a href='#' >
<i class="material-icons" style="vertical-align: middle;">help</i>
</a>
</span>
</div>
</div>
</div>
Then adjust the input-group-addon styling to remove the "grey" that comes default
CSS
.input-group-addon {
padding: 0 6px;
color: inherit;
background-color: transparent;
border: none;
}
JSFIDDLE

Bootstrap 3: Horizontal form group inside dropdown

The requirement is a horizontal form group inside of a dropdown. When the user clicks the dropdown, they are able to enter text into the appearing text fields.
I am losing control over the width and margin of the form group when inside of the dropdown. For example, the following form group renders fine:
<form class="form-horizontal">
<div class="form-group">
<label for="strike-from" class="col-sm-2 control-label">From</label>
<div class="col-xs-1">
<input type="text" class="form-control" id="strike-from" value="">
</div>
</div>
<div class="form-group">
<label for="strike-to" class="col-sm-2 control-label">To</label>
<div class="col-xs-1">
<input type="text" class="form-control" id="strike-to" value=""">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Apply</button>
</div>
</div>
</form>
However when embedding this same HTML inside of a dropdown wrapper, the text fields extend past the container and the margin is compressed.
<div class="form-inline">
<div class="form-group">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="strikes-range" data-toggle="dropdown" aria-haspopup="true">
Strikes
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="strikes">
<li>
<form class="form-horizontal">
<div class="form-group">
<label for="strike-from" class="col-sm-2 control-label">From</label>
<div class="col-xs-1">
<input type="text" class="form-control" id="strike-from" value="">
</div>
</div>
<div class="form-group">
<label for="strike-to" class="col-sm-2 control-label">To</label>
<div class="col-xs-1">
<input type="text" class="form-control" id="strike-to" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Apply</button>
</div>
</div>
</form>
</li>
</ul>
</div>
</div>
</div>
Is there an out of the box implementation of this? Otherwise do I just need to add custom styles for width of text boxes and margin?
Or am I just implementing something incorrectly?
I have edited some column widths and removed an extra " and added a class donotchange for removing the alignment error.
Here is my code
HTML
<div class="form-inline">
<div class="form-group">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="strikes-range" data-toggle="dropdown" aria-haspopup="true"> Strikes <span class="caret"></span> </button>
<ul class="dropdown-menu" aria-labelledby="strikes">
<li style="width: 280px;">
<form class="form-horizontal" style="display:block;">
<div class="form-group donotchange">
<label for="strike-from" class="col-sm-2 control-label">From</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="strike-from" value="">
</div>
</div>
<div class="form-group donotchange">
<label for="strike-to" class="col-sm-2 control-label">To</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="strike-to" value="">
</div>
</div>
<div class="form-group donotchange">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Apply</button>
</div>
</div>
</form>
</li>
</ul>
</div>
</div>
<!-- No need. For checking Only-->
<div class="form-group">
<button class="btn btn-default dropdown-toggle" type="button" id="strikes-range" data-toggle="dropdown" aria-haspopup="true"> Sample Button </button>
</div>
<div class="form-group">
<input type="text" class="form-control" id="strike-to" value="">
</div>
<!-- No need. For checking Only-->
</div>
CSS
#media (min-width: 768px){
.form-inline .donotchange {
display: block;
margin-bottom: 10px;
vertical-align: middle;
}
.form-horizontal .donotchange {
margin-right: 0px;
margin-left: 0px;
}}
#media (min-width: 768px){
.form-inline .donotchange {
display: block;
margin-bottom: 10px;
vertical-align: middle;
}}
Check my working code here http://www.bootply.com/N0lccYSCsg
Check whether it works as per your requirements.
Good day!

Bootstrap 3 form and form last row background color

In our forms, we try to:
Add a background color to the form and
background color to the the last row of the form, which usually contains our buttons.
The problem is that the background color of the last row, is not aligned correctly. You will see that the last row size is exceeded the form width.
Please see:
http://jsfiddle.net/4ThKn/2/
As you noted the black background color is not aligned correctly with the form pink color.
Here is the code, which is same as sample in bootstrap site:
<div class="container">
<div class="row">
<div class="col-md-6">
<form class="form-horizontal" role="form" style="background-color:pink">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox">Remember me</label>
</div>
</div>
</div>
<div class="form-group" style="background-color: black">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
<button type="submit" class="btn btn-default">Ignore!</button>
</div>
</div>
</form>
</div>
<div class="col-md-6">
I am just a sample
</div>
</div>
</div>
Invert your divs try this:
<div class="col-sm-offset-2 col-sm-10" style="background: black">
<div class="form-group">
<button type="submit" class="btn btn-default">Sign in</button>
<button type="submit" class="btn btn-default">Ignore!</button>
</div>
</div>
The problem was each form-group has a left and right margin of -15px, so it's expected that the black part to be 30px wider than the pink part.
To fix it I did as below:
<div style="background-color: black; margin-left: 0px; margin-right: 0px;" class="form-group">
Reference : https://github.com/morteza/bootstrap-rtl/issues/20