Clean positioning of Search button in CSS - 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.

Related

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

Bootstrap 4 form input with icon for validation

In Bootstrap 3 there were optional icons for each of the validation states. The icon would appear in the right side of the input using the has-feedback, has-success, has-danger, etc... classes.
How can I get this same functionality in Bootstrap 4 using the valid-feedback or invalid-feedback classes?
Bootstrap 4 doesn't include icons (glyphicons are gone), and there are now just 2 validation states (is-valid and is-invalid) that control display of the valid-feedback and invalid-feedback text.
With a little extra CSS, you can position an icon inside the input (to the right), and control its' display using is-valid or is-invalid on the form-control input. Use a font lib like fontawesome for the icons. I created a new feedback-icon class that you can add to the valid/invalid-feedback.
.valid-feedback.feedback-icon,
.invalid-feedback.feedback-icon {
position: absolute;
width: auto;
bottom: 10px;
right: 10px;
margin-top: 0;
}
HTML
<div class="form-group position-relative">
<label for="input2">Valid with icon</label>
<input type="text" class="form-control is-valid" id="input2">
<div class="valid-feedback feedback-icon">
<i class="fa fa-check"></i>
</div>
<div class="invalid-feedback feedback-icon">
<i class="fa fa-times"></i>
</div>
</div>
Demo of input validation icons
Demo with working validation
.valid-feedback.feedback-icon,
.invalid-feedback.feedback-icon {
position: absolute;
width: auto;
bottom: 10px;
right: 10px;
margin-top: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="form-group position-relative">
<label for="input2">Valid with icon</label>
<input type="text" class="form-control is-valid" id="input2">
<div class="valid-feedback feedback-icon">
<i class="fa fa-check"></i>
</div>
<div class="invalid-feedback feedback-icon">
<i class="fa fa-times"></i>
</div>
</div>
</div>
Notice that the containing form-group is position:relative using the position-relative class.
Form validation icons are built-in Bootstrap 4.3.1, see documentation here : https://getbootstrap.com/docs/4.3/components/forms/#custom-styles
For a client-side validation, you can use ParsleyJS plugin.
See a demo here : https://jsfiddle.net/djibe89/tu0ap111/
Fake code
a simple way to do it with bootstrap 4 is:
<div class="input-group mb-3 border border-success">
<input type="text" class="form-control border-0" aria-label="Amount (to the nearest dollar)">
<div class="input-group-append">
<span class="input-group-text bg-white border-0 text-success"><span class="iconify" data-icon="subway:tick" data-inline="true"></span></span>
</div>
</div>
obviously you have to include
<script src="https://code.iconify.design/1/1.0.4/iconify.min.js"></script>

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>

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 font not reflecting - for bootswatch theme

I'm very noob in bootstrap. I tried my first bootstrap page and then downloaded a theme from bootswatch.com and replaced the bootstrap.css with the Cerulean theme. When I change the font in the bootstrap.css it stay with the old theme
#import url(//fonts.googleapis.com/css?family=Caesar+Dressing);
but its not reflecting when I refresh my page.
<!DOCTYPE html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script>
<link href="css/bootstrap.css" rel="stylesheet">
<title>Twitter Bootstrap Tutorial - A responsive layout tutorial</title>
<style type='text/css'>
</style>
<script>
$(function() {
// Setup drop down menu
$('.dropdown-toggle').dropdown();
// Fix input element click problem
$('.dropdown input, .dropdown label').click(function(e) {
e.stopPropagation();
});
});
</script>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container"><!-- Collapsable nav bar -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Your site name for the upper left corner of the site -->
<a class="brand">GUVI</a>
<!-- Start of the nav bar content -->
<div class="nav-collapse"><!-- Other nav bar content -->
<!-- The drop down menu -->
<ul class="nav pull-right">
<li>Sign Up</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<form action="[YOUR ACTION]" method="post" accept-charset="UTF-8">
<input id="user_username" style="margin-bottom: 15px;" type="text" name="user[username]" size="30" />
<input id="user_password" style="margin-bottom: 15px;" type="password" name="user[password]" size="30" />
<input id="user_remember_me" style="float: left; margin-right: 10px;" type="checkbox" name="user[remember_me]" value="1" />
<label class="string optional" for="user_remember_me"> Remember me</label>
<input class="btn btn-primary" style="clear: left; width: 100%; height: 32px; font-size: 13px;" type="submit" name="commit" value="Sign In" />
</form>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>
You're linking to the right font, yeah; that said, here's my take on this:
In most cases you should use a tag to import Google web fonts. I generally avoid using #import where possible because it delays the loading of the file.
All you should need to do to replace the font is to specify the new font-family as 'Caesar Dressing' inside a body {} style block. Assuming you've already done that in your local copy of bootstrap.css, if that still doesn't work try specifying it inside a tag inside your HTML. You should avoid doing that where possible though; it makes it annoying down the road when you have multiple pages to maintain.
One other thing: I noticed you have some inline styles for some of your inputs. You should really avoid using those where possible--it's good form to try and separate presentation and content markup as much as possible.

Resources