uib-typeahead dropdown width - css

I have the following html structure
<div class="search">
<div class="input-group">
<div class="input-group-btn" ng-show="categoryEnabled === true">
<div isteven-multi-select
input-model="categories"
output-model="chosenCategories">
</div>
</div>
<div class="typeahead-search">
<input type="text" ng-model="searchData.searchTerm"
placeholder="{{searchPlaceHolder}}"
class="form-control typeahead"
focus-on="categoryComplete" typeahead-min-length="2"
uib-typeahead="item.DisplaySearchText as
item.DisplaySearchText for item in
getProductsForTypeahead($viewValue)">
</div>
<span class="input-group-btn">
<button class="btn btn-default btn-search">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>
</div>
</div>
I set the width of typeahead-search div to 100%.
But the width of the typeahead is bigger than the div.
Upon inspection, the typeahead's width of 100% takes it from the topmost div (class="search")
How do I make it the same width as the input?
Thanks in advance.
NM

Since .dropdown-menu is positioned absolute, adding position: relative; to the div wrapping around your uib-typeahead input field and setting width: 100%; to your .dropdown-menu will fix it.
Your CSS would look something like this:
.typeahead-search {
position: relative;
}
.dropdown-menu {
width: 100%;
}

Related

Aligning a span to fall underneath an input box

I have the code below for a blazor component which displays a textbox that can be edited with the click
of a button.
#if (_editing)
{
<div class="floatingbox position-relative">
<input type="text" value="#AddText" #oninput="#(e => { AddText = e.Value.ToString(); })"
#onblur="#(e => { InputBlured(e); })" #onkeyup="#(e => KeyPressed(e))" maxlength="75" />
<button type="button" class="button_search_term">
<div #onclick="ProcessInput"><i class="fas fa-arrow-right"></i></div>
</button>
</div>
}
else
{
<div class="floatingbox position-relative" #ondblclick="ToggleMode">
<span>#AddText</span>
</div>
}
I want to display this span right under the input box for error messages
<span hidden="#IsShow" class="error-color">Error message</span>
I wrote this css and used display block but what happens is everytime there is an error
the span above is enabled and rearranges the input box controls underneath one another. There can be many of these controls
on a page.
.error-color{
color:red;
//display:block;
padding-left:35px;
}
How can I style this such that the span stays directly under the inputbox?
You can achieve this with position:absolute
See this example:
.control{
position: relative;
}
.error{
position: absolute;
left: 0;
bottom: -10px;
font-size: 10px;
line-height: 1;
}
<div class="control">
<input type="text">
<span class="error">ERROR</span>
</div>
Keep in mind that you have to put position:relative to the parent Element.
Your final HTML shoudl look something like this:
<div class="floatingbox position-relative">
<input type="text" value="#AddText" #oninput="#(e => { AddText = e.Value.ToString(); })" #onblur="#(e => { InputBlured(e); })" #onkeyup="#(e => KeyPressed(e))" maxlength="75" />
<button type="button" class="button_search_term">
<div #onclick="ProcessInput"><i class="fas fa-arrow-right"></i></div>
</button>
<!-- insert your error span here -->
<span hidden="#IsShow" class="error-color">Error message</span>
</div>

CSS - One big Text field between two big buttons

I have 2 big buttons and a text field between them. At the moment, it looks like this:
But I am trying to get it to look like this:
Here is my code:
.input-group-btn {
width: 90%;
height: 90%;
}
#quantity {
font-size: 40px;
width: 5%;
height: 90%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.1/css/all.css">
<div class="col-md-12 offset-md-4">
<div>
<span> <button type="button" class="quantity-left-minus btn btn-danger btn-number" style="font-size: 50px;" data-type="minus" data-field=""> <span class="fa fa-minus-circle"></span> </button>
</span>
<span><input type="text" id="quantity" name="quantity" class="input-number" value="1" min="1" max="100"></span>
<span><button type="button" class="quantity-right-plus btn btn-success btn-number" style="font-size: 50px;" data-type="plus" data-field=""> <span class="fa fa-plus-circle"></span> </button>
</span>
</div>
<br>
<br>
<span>STAMPA</span>
</div>
I added .buttons-wrapper { display: flex; align-items: center; } to make it aligned vertically, and some padding to the text input,
Check this code:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div class="col-md-12 offset-md-4">
<div class="buttons-wrapper">
<span>
<button type="button" class="quantity-left-minus btn btn-danger btn-number" style="font-size: 50px;"
data-type="minus" data-field="">
<span class="fa fa-minus-circle"></span> </button> </span>
<span>
<input type="text" id="quantity" name="quantity" class="input-number" value="1" min="1" max="100">
</span>
<span>
<button type="button" class="quantity-right-plus btn btn-success btn-number" style="font-size: 50px;"
data-type="plus" data-field=""> <span class="fa fa-plus-circle"></span> </button></span>
</div>
<br>
<br>
<span><a href="" class="btn btn-primary btn-lg active" role="button" aria-pressed="true" style=" font-size: 50px;"
id="printLabel" onclick="dowloadFileJS()">STAMPA</a></span>
</div>
<style>
.input-group-btn {
width: 90%;
height: 90%;
}
.buttons-wrapper {
display: flex;
align-items: center;
}
#quantity {
font-size: 40px;
width: 65px;
padding: 12.5px 0;
margin: 0 10px;
}
</style>
Why did you wrap your elements in <span> ?
Personally I would get rid of all the unnecessary <span>, and if I need to wrap any element I would use <div>.
Sizes in percentag refer to the parent's size.
The parents of .input-group-btn and #quantity are <span> elements.
<span> is an inline element. That means it cannot have a fixed size (height, width, margin cannot be defined). They match to their children's size.
Since your <input> and <button> do not have a fixed size defined, they are sized to default. So the parent inline element (<span>) also sizes to that default.
Then your height: 90% is computed. Relating to the parent that has no fixed size.
That means your <input> and <button> are just scaled down to 90% from their default height.
Hint: It is always tricky to use percentage values for sizing and is therefore not recommended for every case.
See also:
CSS – why doesn’t percentage height work?
Percentage Height HTML 5/CSS
I've added some padding to the text input box to increase the height and added some offset from the top to align. This is of course if you must keep the span elements. https://jsfiddle.net/31v0aupc/1/.
#quantity{
font-size: 40px;
width:5%;
height:85%;
padding: 18px 0;
position: relative;
top:10px;
}
If you can, try using inline-flex.
div {
display: inline-flex;
align-items: center;
}

How do I apply a max-width to an input field form-control with a trailing secondary button in Bootstrap 3?

When I attempt to apply a maximum width to an input field, it positions the secondary button as if the input field didn't have a maximum width.
JSFiddle Example
HTML:
<div class="container">
<div class="form-group">
<label class="control-label">Date</label>
<div class="input-group">
<input type="text" maxlength="10" class="form-control datefield" placeholder="mm/dd/yyyy">
<span class="input-group-btn">
<button id="btnClearDate" class="btn btn-secondary btn-default" type="button">Clear</button>
</span>
</div>
</div>
</div>
CSS:
.datefield {
max-width: 100px;
}
Result:
How can I get the secondary button to correctly sit next to the text field?
Try using display:inline-block;
https://jsfiddle.net/ex3ntia/DTcHh/22030/
.input-group-btn {display:inline-block;}
Bootstrap is laid out by using a grid system. You will need to adjust your design layout to accomplish what you are looking to achieve.
What is happening now is all you are doing is shrinking down the size of the input box, but not the actual grid cell.
try adjusting just the cell or placing the form-group elements within a cell then within a targeting element you can shrink.
Try this,
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
padding: 10px;
}
.shrink {
width: 200px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="form-group">
<div class="shrink">
<label class="control-label">Date</label>
<div class="input-group">
<input type="text" maxlength="10" class="form-control datefield" placeholder="mm/dd/yyyy">
<span class="input-group-btn">
<button id="btnClearDate" class="btn btn-secondary btn-default" type="button">Clear</button>
</span>
</div><!-- .input-group -->
</div><!-- .shrink -->
</div><!-- .form-group -->
</div><!-- .row -->
</div> <!-- .container -->
Hope that helps!
The span was not being displayed inline. I assume this was changed with the input-group-btn class. Here is the new code (I named the new class ):
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
.datefield {
max-width: 100px;
}
.buttoncleardiv {
display: inline;
}
<div class="container">
<div class="form-group">
<label class="control-label">Date</label>
<div class="input-group">
<input type="text" maxlength="10" class="form-control datefield" placeholder="mm/dd/yyyy">
<span class="input-group-btn buttoncleardiv">
<button id="btnClearDate" class="btn btn-secondary btn-default" type="button">Clear</button>
</span>
</div>
</div>
The JS Fiddle is here

Bootstrap Navbar Keep Elements on Same Line When Collapsed

I am using a Bootstrap navbar and using it's collapse functionality.
In my fully expanded navbar, I have three elements - a search field and it's button, and also a browse button.
When it collapses, I would like to have the search field and it's submit button to appear on the same line. However, when my navbar collapses, it places the search field on it's own line, and then the "submit" and "browse" button on the same line. The image below shows what I mean.
I would like it to have the search field and the glyphicon 'submit' button on one line, and the browse button on the line below.
Here is the html I am using:
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control">
</div><!--
--><button type="submit" class="btn btn-default btn-search"">
<span class="glyphicon glyphicon-search"></span>
</button>
<button type="submit" class="btn btn-default">Browse</button>
</form>
</div>
Put you button inside the form-group,
<div class="form-group">
<input type="text" class="form-control">
<button type="submit" class="btn btn-default btn-search">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
add this to your CSS,
.navbar-form .form-group input {
width: calc(100% - 50px);
display: inline-block;
vertical-align: top;
}
and here is a fiddle demo
try this one
.form-control{display:inline-block;width:80%}.btn-search{width:10%}
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control"><button type="submit" class="btn btn-default btn-search"">
<span class="glyphicon glyphicon-search"></span>
</button></div>
<button type="submit" class="btn btn-default">Browse</button>
</form>
</div>
At mobile screens you can position your search button to absolute and then place it over the search input to the right and then give the input a padding to the right and it will appear to be on the same line. So first position your .navbar-form to relative and then at mobile widths positon your search button to absolute and then give the the search input a padding right to make up for the button being placed over the top of it like so:
Here is a fiddle Fiddle
.navbar-form{
position: relative;
}
#media screen and (max-width: 767px){
.navbar-form .btn-search{
position: absolute;
right: 15px;
top: 10px;
}
.navbar-form input{
padding-right: 40px;
}
}

Bootstrap input-group-addon Not Vertically Aligned

I'm using the following markup with Bootstrap:
<div class="row">
<label class="col-md-4">Date of Completion of Checklist</label>
<div class="col-md-4">
<div class="input-group">
<input type="text" class="form-control datepicker">
<span class="input-group-addon glyphicon glyphicon-calendar"></span>
</div>
</div>
</div>
I have some of my own CSS in a separate file, including:
.form-control {
border-color: #000;
border-radius: 0;
box-shadow: none;
}
.form-control:focus {
border-color: #009966;
}
label {
font-weight: bold;
margin-top: 8px;
}
.input-group-addon {
background: #fff;
border-color: #000;
}
However, even when I remove my whole custom stylesheet, I am still presented with this vertical alignment issue you can see below:
It looks like it's 1 pixel off what it should be. I've tried setting the positioning to relative and set bottom: 1px however it doesn't appear to budge.
If I remove the vertical-align property it completely messes up the look of it.
Does anyone have an idea what could be causing the problem?
.glyphicon {
top: 1px;
}
change this to top:0px; or add style="top:0px;" top your span
Changing your html to this fixes it:
<div class="row">
<label class="col-md-4">Date of Completion of Checklist</label>
<div class="col-md-4">
<div class="input-group">
<input type="text" class="form-control datepicker"/>
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
</div>
i have moved the glyphicon glyphicon-calendar class to an <i> inside your span, which now aligns all correctly.
Try some thing like this input-group-addon and place span above input
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-calendar"></i></span>
<input type="text" class="form-control datepicker" aria-describedby="basic-addon1">
</div>
http://getbootstrap.com/components/#input-groups

Resources