CSS - One big Text field between two big buttons - css

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

Related

uib-typeahead dropdown width

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

How can I horizontally align 2 spans in the same line?

I have 2 spans in the same line with several elements in each one.
How can I add css styles to my 2 spans and make one be centered, the other one in the same line shouldn't move the previous one (centered), but it should bind to its right corner.
HTML
<span><!-- should be centered-->
<a id="3"></a><span id="2"> ..... </span>
<a id="1">...</a>
</span>
<span><!-- left corner of this span should meet the right corner of the previous span -->
<label>something</label><input type="text" id="5">
<input type="button" />
</span>
<span class="mrRight"><!-- float right here --> ...... </span>
You need to set the first spans margin-left to 48%. Or if you want to be precise, margin-left: calc(50% - x), where x is half of the width of the first span.
fiddle
Note: the gradient is there just to show you where the center is :)
.center { margin-left: calc(50% - 26px) }
To achieve this firstly you need to add a wrapper around the spans like so
HTML
<div class="span_wrapper">
<span>
<a id="3"></a><span id="2"> center </span>
<a id="1">center</a>
</span>
<span>
<label>something</label>
<input type="text" id="5"> <input type="button" />
</span>
<span class="mrRight"> right </span>
</div>
Now the appropriate CSS should be
.span_wrapper {
text-align: center;
}
.span_wrapper .mrRight{
float: right;
}
.span_wrapper {
text-align: center;
}
.span_wrapper .mrRight{
float: right;
}
<div class="span_wrapper">
<span>
<a id="3"></a><span id="2"> center </span>
<a id="1">center</a>
</span>
<span>
<label>something</label>
<input type="text" id="5"> <input type="button" />
</span>
<span class="mrRight"> right </span>
</div>

Clean positioning of Search button in CSS

Given the following example, what would be a good approach to position the Search button in line with the date input controls?
I gave it a shot with Bootstrap (2 rows, 3 columns) but the layout should stick to the left and keep the 3 logical columns together. And maybe there's an easier solution I am overlooking.
JS Bin HTML
Note: based on the simplified output from Telerik's Kendo UI combined with ASP.NET MVC.
Flexbox requires IE10+
Here is the solution that works everywhere and won't break bootstrap's responsiveness http://output.jsbin.com/ladezahija/1/
Idea is to apply to elements (blocks with date and search button) next rule:
.element {
display: inline-block;
vertical-align: bottom;
}
In an example I had to use float: none to redefine previously added property by bootstrap.
Also make sure you add a separate class for container and inner elements you work on.
I would go with CSS Flex.
using this CSS would align them for you. (you will need some vendor prefixes)
$("#datepicker").kendoDatePicker();
$("#grid").kendoGrid({
dataSource: [
{ foo: "foo", bar: "bar" }
]
});
.container-fluid {
display: flex;
justify-content: space-around;
}
.container-fluid > div {
align-self: flex-end;
}
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<div class="container-fluid">
<div style="margin: 20px; float: left;">
<h4>
<label for="StartDate">From</label>
</h4>
<span class="k-widget k-datepicker k-header">
<span class="k-picker-wrap k-state-default">
<input name="startDate" class="k-input" id="startDate" role="combobox" aria-disabled="false" aria-expanded="false" aria-readonly="false" aria-owns="startDate_dateview" style="width: 100%;" type="text" value="1-11-2015" data-val="true" data-role="datepicker" />
<span class="k-select" role="button" unselectable="on">
<span class="k-icon k-i-calendar" unselectable="on">select</span>
</span>
</span>
</span>
</div>
<div style="margin: 20px; float: left;">
<h4>
<label for="EndDate">To</label>
</h4>
<span class="k-widget k-datepicker k-header">
<span class="k-picker-wrap k-state-default">
<input name="endDate" class="k-input" id="endDate" role="combobox" aria-disabled="false" aria-expanded="false" aria-readonly="false" aria-owns="endDate_dateview" style="width: 100%;" type="text" value="24-12-2015" data-val="true" data-role="datepicker" />
<span class="k-select" role="button" unselectable="on">
<span class="k-icon k-i-calendar" unselectable="on">select</span>
</span>
</span>
</span>
</div>
<div style="margin: 20px; float: left;">
<button tabindex="0" class="k-button" id="applyFilters" role="button" aria-disabled="false" data-role="button">Search</button>
</div>
</div>
You didn't used bootstrap properly. Anyway I have two solution.
First Solution:=> Add a blank h4 <h4> </h4> into last div.
Second Solution:=> Use margin-top:60px to k-button.

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

Span adding unexpected height to sibling

I am having trouble adding a validation indicator to my input fields in my creditcards form.
For some reason, having the span adds height to the span.input-group-addon, resulting in empty space below the input
<template name="checkoutForm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Title</h4>
</div>
<div class="modal-body">
<form class="bs-example bs-example-form">
<div class="no-margin">
<div class="col-xs-12">
<div class="input-group">
<span class="input-group-addon input-group-sm"><i class="fa fa-credit-card"></i></span>
<input type="text" class="form-control" id="checkoutCardNumber" placeholder="Card Number">
<span class="validity"></span>
</div>
</div>
And LESS
#import '../../../../stylesheets/variables.import.less';
#import '../../../../stylesheets/mixins.import.less';
.checkout-form {
max-width: 350px;
margin: auto;
.no-margin {
.form-group {
width: 80%;
margin: 0px;
}
}
.validity {
overflow: auto;
position: relative;
top: -27px;
left: 215px;
z-index: 1000;
.valid {
color: #brand-primary;
}
.invalid {
color: red;
}
}
}
How can I correct this?
One way of getting rid of the extra whitespace is removing the line feeds or spaces between elements
You can change
<input type="text" class="form-control" id="checkoutCardNumber" placeholder="Card Number">
<span class="validity"></span>
to
<input type="text" class="form-control" id="checkoutCardNumber" placeholder="Card Number"><span class="validity"></span>
Another way is to set the parent element class' font-size attribute to zero.
So try adding
font-size:0;
white-space:nowrap;
to input-group class. Or change the markup as follows
<div class="input-group" style="font-size:0;white-space:nowrap;">
But then you have to specify the font-size attribute in validity class in order to display the text within.
Another way is to add
float:left;
to validity class. You'll probably have to add that to input's class too.
EDIT
It appears that the problem has nothing to do with the issues above.
Simply remove <span class="validity"></span> outside of <div class="input-group"> as follows and see if that works
<div class="input-group">
<span class="input-group-addon input-group-sm"><i class="fa fa-credit-card"></i></span>
<input type="text" class="form-control" id="checkoutCardNumber" placeholder="Card Number">
</div>
<span class="validity"></span>
EDIT 2
Change validity class as follows
.validity {
overflow: auto;
position: absolute;
top: 5px;
left: 215px;
z-index: 1000;
}
and use the markup below (your original)
<div class="input-group">
<span class="input-group-addon input-group-sm"><i class="fa fa-credit-card"></i></span>
<input type="text" class="form-control" id="checkoutCardNumber" placeholder="Card Number">
<span class="validity"></span>
</div>

Resources