How to add in input form button cancel - html

I would like to do something like this.
but i dont know how to do it in Bootstrap correctly
Here's my html code where i get only like this.
<form class="navbar-form" role="search">
<div class="input-group add-on">
<input type="text" [(ngModel)]="text" class="form-control" placeholder="Search" name="text">
<button class="btn btn-default" type="submit" (click)="clear()"><i class="glyphicon glyphicon-remove"></i></button>
<div class="input-group-btn">
<button class="btn btn-default" type="submit" (click)="search()"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>

I honestly think that buttons are a pain in the butt and are outdated. I much rather use a simple div, a or in this case i tag.
Therefore this might not be completely what OP asked for but in my eyes it is a more elegant solution.
The secret to this solution is using the flex property to the wrapper, which makes it possible to automatically size its children within its space.
.field {
display: flex;
position: relative;
max-width: 285px;
min-width: 200px;
width: 100%;
flex-direction: row;
}
Please check out the snippet for a more specific example. This works in all modern browsers and from internet explorer 10.
var input = document.getElementById("search");
function clearInput() {
input.value = "";
}
function search () {
console.log("searching");
// Implement search function here...
}
.field {
display: flex;
position: relative;
max-width: 285px;
min-width: 200px;
width: 100%;
flex-direction: row;
}
.field > input[type=text] {
flex: 1;
padding: 0.6em 0.6em 0.6em 1.5em;
border: 1px solid #c4c4c4;
border-right: none;
display: block;
}
.field > div {
padding: 0.4em 0;
background-color: #fff;
border: 1px solid #c4c4c4;
border-left: none;
border-radius: 1px;
display: inline-block;
cursor: pointer;
}
.field > div > i {
padding: 0.2em 0.8em;
background-color: inherit;
color: #555555;
border: none;
border-left: 1px solid #c4c4c4;
margin-right: 1px;
}
.field > div:last-child > i {
border-left: none;
}
.field > div:hover > i {
color: #009BDB;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<div class="field">
<input type="text" id="search" placeholder="Search..." />
<div>
<i class="fa fa-times" onclick="clearInput()"></i>
</div>
<div>
<i class="fa fa-search" onclick="search()"></i>
</div>
</div>

You could play around with position: relative,
for example:
html:
<form class="navbar-form" role="search">
<div class="input-group add-on">
<input type="text" [(ngModel)]="text" class="form-control" placeholder="Search" name="text">
<button class="btn btn-default test" type="submit" (click)="clear()"><i class="glyphicon glyphicon-remove"></i></button>
<div class="input-group-btn">
<button class="btn btn-default" type="submit" (click)="search()"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
css:
.form-control {
position:relative;
}
.test {
position:relative;
right:20px;
}
example jsfiddle: https://jsfiddle.net/DTcHh/92025/

Related

How can set element alignment which is inside parent with the child style setting in element style attributes?

.popup {
position: relative;
display: inline-block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
I have above codes in my css file that added in html head <link href="/static/styles.css" rel="stylesheet">
In my html there where many uses of .popupand .popuptext and I wont change above styles.
In the html code is here↓
<div class="popup" style="display: inline"><div class="popuptext" id="tableHeader">
<label>data type</label>
<br>
<input type="checkbox" name="not_null"> NOT NULL
<br>
<input type="checkbox" name="unique"> UNIQUE
<br>
<button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div></div>
All elements above are aligned as center.
But I need centralize the Delete button and the label and other input elements be left aligned.
As I consist change style from html code and stylesheet has other uses, I have tried below↓
<div class="popup" style="display: inline"><div class="popuptext" id="tableHeader">
<label>data type</label>
<br>
<span style="text-align: left;"><input type="checkbox" name="not_null"> NOT NULL</span>
<br>
<span style="text-align: left;"><input type="checkbox" name="unique"> UNIQUE</span>
<br>
<button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div></div>
But input elements remain centralist and not left aligned!
I need input get left aligned only with change style settings in html element attributes.
Leaving the html as it is, you could style the .popuptext children as display:block so that they will take the whole width. Then you can style indipendently its parts:
The <label> element - its content gets centered with text-align: center
The <input> elements - they get aligned to left with text-align: left; but just because we are actually styling their parents
<span>
The <button> element - this required margin: 0 auto meaning that the left
and right margins will be set to the maximum available space in the
row
Everything else in the styles here in the demo is for decoration purpose.
.popup{
border: solid;
width: 10em;
background: lightgray;
}
.popuptext > *{
display: block;
}
.popuptext > span{
text-align: left;
}
.popuptext > label{
text-align: center;
margin-bottom: .5em;
}
.popuptext > button{
margin: .5em auto;
border: none;
background: red;
color: white;
padding: .8em .6em;
border-radius: 5px;
}
<div class="popup">
<div class="popuptext" id="tableHeader">
<label>data type</label>
<span><input type="checkbox" name="not_null"> NOT NULL</span>
<span><input type="checkbox" name="unique"> UNIQUE</span>
<button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div>
</div>
You can restructure your HTML and CSS as such:
.popup .popuptext {
width: 160px;
background-color: #555;
color: #fff;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
}
.popuptext .checkbox-holder {
width: fit-content;
margin: auto;
}
<div class="popup" style="display: inline">
<div class="popuptext" id="tableHeader">
<div style="text-align: center;"><label>data type</label></div>
<div class="checkbox-holder">
<div><input type="checkbox" name="not_null" id="not_null"> <label for="not_null">NOT NULL</label></div>
<div><input type="checkbox" name="unique" id="unique"> <label for="unique">UNIQUE</label></div>
</div>
<div style="text-align:center"><button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div>
</div>
</div>

HTML Buttons with size not equal to each other since code is exactly the same

I am wondering why my buttons aren't equal to each other since both HTML and CSS code is exactly the same.
HTML code:
<div class="export-left">
<button type="button" class="formreturn" value="Copy Url" onclick="Copy();">Copy Url</button>
<label><input type="text" class="txtfilename" id="op-text-filename" placeholder="type file name"/>.txt</label>
<button type="button" class="formreturn" onclick="saveURLtoTXTfile();"><span class="glyphicon glyphicon-download"></span>.TXT</button>
</div>
<div class="export-right">
<button type="button" class="excelsubmit" onclick="exportData()"><span class="glyphicon glyphicon-download"></span>.CSV</button>
<button type="button" id="btnExport" class="excelsubmit" onclick="fnExcelReport();"><span class="glyphicon glyphicon-download"></span>.XLS </button>
</div>
CSS
.export {
display: flex;
align-items: flex-start;
}
.export-left {
display: flex;
}
.export-right {
margin-left: auto;
}
.formreturn {
font-weight:700;
text-decoration: none;
color:black;
background:#c6e2f2;
padding: 8px;
border-radius: 3px;
}
.excelsubmit {
font-weight:700;
float: right;
padding: 8px;
background:#c6e2f2;
border-radius: 3px;
}
Where have I made mistake? I want these buttons in the same size (height) roughly. Unfortunately, the padding didn't work here.
Give each button an additional class like
<button type="button" class="btn formreturn"
Then in your CSS give the class btn a minimum width
CSS
.btn{
min-width: 100px;
}
Apply this:
.export-left {
display: flex;
align-items: flex-start;
}
In your example, the export class isn't used, after wrapping your code in that class everything is aligned.
Like so:
body {
padding: 20px; /* for demo */
}
.export {
display: flex;
align-items: flex-start;
}
.export-left {
display: flex;
}
.export-right {
margin-left: auto;
}
.formreturn {
font-weight: 700;
text-decoration: none;
color: black;
background: #c6e2f2;
padding: 8px;
border-radius: 3px;
}
.excelsubmit {
font-weight: 700;
float: right;
padding: 8px;
background: #c6e2f2;
border-radius: 3px;
}
<div class="export">
<div class="export-left">
<button type="button" class="formreturn" value="Copy Url" onclick="Copy();">
Copy Url
</button>
<label>
<input type="text" class="txtfilename" id="op-text-filename" placeholder="type file name" />.txt
</label>
<button type="button" class="formreturn" onclick="saveURLtoTXTfile();">
<span class="glyphicon glyphicon-download"></span>.TXT
</button>
</div>
<div class="export-right">
<button type="button" class="excelsubmit" onclick="exportData()">
<span class="glyphicon glyphicon-download"></span>.CSV
</button>
<button type="button" id="btnExport" class="excelsubmit" onclick="fnExcelReport();">
<span class="glyphicon glyphicon-download"></span>.XLS
</button>
</div>
</div>

Div under input field

I want to display a div exactly below an input field. Of course, it's simple to achieve this, but I want this to work also with mobile. It's not working to good with media queries, so is there another way?
It's a live search. I want the div #display to be exactly under the input.
It's working on desktop machines, but not on mobile devices. Is there a general way or do I really have to use media queries with a fixed margin, width, and height?
#display {
background-color: #f2f2f2;
position: absolute;
width: 227px;
border: solid;
border-top: none;
border-radius: 0px 0px 5px 5px;
border-width: thin;
z-index: 1 !important;
}
.live-search {
min-height: 30px;
display: flex;
align-items: center;
}
<form class="form-inline my-2 my-lg-0" action="search.php" method="post" autocomplete="off">
<input type="search" name="search" required="" placeholder="Search">
<button class="btn my-2 my-sm-0" id="search-btn" type="submit">Search</button>
</form>
<div id="display" style="display: block;">
<a href="candidate.php?id=82925298">
<div class="live-search">
<li>82925298, Webdeveloper</li>
</div>
</a>
</div>
#display {
background-color: #f2f2f2;
width: 181px;
border: solid;
border-top: none;
border-radius: 0px 0px 5px 5px;
border-width: thin;
z-index: 1 !important;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<form action="search.php" method="post" ...>
<input type="search" name="search" ...>
<button id="search-btn" type="submit">
Search
</button>
</form>
<div id="display">
<a href="candidate.php?id=82925298">
<div class="live-search">
<li>82925298, WebDeveloper</li>
<li>82925299, WebDesigner</li>
</div>
</a>
</div>

Bootstrap Navbar Expands when Window gets smaller

Regular
Smaller
My bootstrap 3.0 navbar expands when the window gets to mobile sizes. I've included pictures of the two views above and where the issue is.
I am trying to get my navbar to not expand when the screen gets smaller and cover part of my page.
It may have something to do with the search bar and the buttons near it. I managed to get the search form stay the same size when it expanded across the entire screen behind the sidebar before.
Any help would be great.
HTML
`
<a class="navbar-brand" style="margin-left: -20px">GCImage</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-right">
<form class="navbar-form" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" align="right" ng-model="nav.keyword" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
</div>
<button type="submit" class="btn btn-default" align="right" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
<i class="fa fa-search"></i>
</button>
<a class="btn btn-default" href="underConstruction.html"><i class="fa fa-filter"></i></a>
</form>
</div>
</div>
`
CSS
.panel-green {
border-color: #5cb85c;
background-color: #5cb85c;
color: #ffffff;
}
.panel-orange {
border-color: #ff7e47;
background-color: #ff7e47;
color: #ffffff;
}
.shadow {
-moz-box-shadow: 1px 1px 2px 3px #ccc;
-webkit-box-shadow: 1px 1px 2px 3px #ccc;
box-shadow: 1px 1px 2px 3px #ccc;
}
.panel-footer {
color: #000000;
}
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
.body{
margin-left:175px
}
.navbar .navbar-form{
padding: 0 15px;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.box{
border-radius:0;
}
.navbar-collapse.collapse{
display: block !important;
}
.navbar-nav>li, .navbar-nav{
float: left !important;
}
.navbar-nav.navbar-right:last-child{
margin-right: -15px !important;
}
.navbar-right{
float: right !important;
}
It looks like the icons are wrapping underneath the search bar
I played around with your code a little and came up with a solution, however the icons eventually wrap when the screen gets really small (less than 250px wide)
Try changing this code:
<button type="submit" class="btn btn-default" align="right" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
<i class="fa fa-search"></i>
</button>
<a class="btn btn-default" href="underConstruction.html"><i class="fa fa-filter"></i></a>
To this code:
<div class="icons">
<ul class="icon-list">
<li class="icon">
<button type="submit" class="btn btn-default" align="right" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
<i class="fa fa-search"></i>
</button>
</li>
<li class="icon">
<a class="btn btn-default" href="underConstruction.html"><i class="fa fa-filter"></i></a>
</li>
</ul>
</div>
And add this to your stylesheet:
.icons {
float: right;
}
ul.icon-list {
padding: 0px;
margin: 0px 0px 0px 4px;
}
li.icon {
display: inline;
list-style: none;
}
.form-group {
display: inline-block !important;
}
This solution isn't perfect, and could be improved (make a backup of your old code before trying this)
Just add
.navbar-header{
display: inline-block; or display: inline-block!important;
}
in your stylesheet. I hope this is what you expect. :)

How can I normalize the implied minimum width of flex-items across the latest versions of major browsers

Edit This may be close to a duplicate, but unfortunately the answer to that question does nothing for IE 11. IE is an implied requirement for a question asking for a cross-browser solution.
I've got a jsfiddle showing the issue.
The first .flex-container is closest to how things are built in my application. This renders "correctly" in chrome, but if you pull it up in IE 11, or Firefox ≈38 the inputs overflow the parent .flex-container.
This issue doesn't seem to listed among the known issues on caniuse.com. I can't directly attribute it to one of these flexbugs either.
Can somebody please shed some light on this inconsistency?
Here is an image of Chrome's rendering:
and here is one from IE 11:
I've tried paring the example down with the subsequent containers, and the inputs seem to be the problem. The exception is in the second Chrome container where the existence of the <label> element seems to throw off the width calculation slightly.
I really don't want to define widths on the immediate children of .flex-container if I don't have to. I'd like to use the simplicity of the flex-grow property so that I can add children at some later point.
Thanks.
The problem is that the Flexbox module changes the initial value of min-width:
4.5 Implied Minimum Size of Flex Items
To provide a more reasonable default minimum size for flex items,
this specification introduces a new auto value as the initial
value of the min-width and min-height properties defined in
CSS 2.1.
Chrome hasn't implemented it yet, that's why it seems to work there.
On Firefox, you can fix it using How can I get FF 33.x Flexbox behavior in FF 34.x?
#import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css';
#import 'http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css';
html {
font-size: 62.5%;
}
body {
font-family:"Segoe UI", "Open Sans", Arial, sans-serif;
font-size: 1.4rem;
line-height: 1.42857143;
background-color: #424242;
}
* {
box-sizing: border-box;
}
.flex-container, .input-group, .input-group-btn {
display:flex;
}
.flex-container {
width:600px;
border: 1px solid red;
padding: 1.6rem;
margin: 1.6rem;
}
.flex-container > * + * {
margin-left: 2.5rem;
}
label {
margin-bottom: 5px;
font-size: 1.8rem;
color:white;
}
.form-control {
flex-grow:1;
height: 50px;
padding: 0.6rem 12px;
border:0 none;
text-align:center;
}
.input-group-btn {
flex-basis: 62px;
flex-shrink:0;
}
.input-group-btn button.btn {
flex-grow: 1;
flex-shrink:0;
border: 0 none
}
.input-group-btn > .btn {
position: relative;
}
.form-control, .input-group-btn .btn {
font-size: 2.4rem;
}
.input-group .input-group-btn > .btn {
border-top: 0 none;
border-bottom: 0 none;
}
.flex-item {
background: white;
height: 50px;
}
.flex-container > * {
flex: 1 1 auto;
min-width: 0;
}
.form-control {
min-width: 0;
max-width: 100%;
}
<div class="flex-container">
<div class="form-group">
<label class="control-label">Start Date</label>
<div class="input-group date date-picker">
<input class="form-control" type="text" placeholder="mm/dd/yy"/>
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label">End Date</label>
<div class="input-group date date-picker">
<input class="form-control" type="text" placeholder="mm/dd/yy" />
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
</div>
<div class="flex-container">
<div class="form-group">
<label class="control-label">Start Date</label>
<input class="form-control" name="start-date" type="text" placeholder="mm/dd/yy" />
</div>
<div class="form-group">
<label class="control-label">End Date</label>
<input class="form-control" name="end-date" type="text" placeholder="mm/dd/yy" />
</div>
</div>
<div class="flex-container">
<input class="form-control" name="start-date" type="text" placeholder="mm/dd/yy" />
<input class="form-control" name="end-date" type="text" placeholder="mm/dd/yy" />
</div>
<div class="flex-container">
<div class="flex-item">asdf</div>
<div class="flex-item">asdf</div>
</div>
However, IE needs other changes:
.flex-container > * {
flex: 1; /* Use `flex-basis: 0%` instead of your `auto` */
}
.form-control {
width: 100%;
}
#import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css';
#import 'http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css';
html {
font-size: 62.5%;
}
body {
font-family:"Segoe UI", "Open Sans", Arial, sans-serif;
font-size: 1.4rem;
line-height: 1.42857143;
background-color: #424242;
}
* {
box-sizing: border-box;
}
.flex-container, .input-group, .input-group-btn {
display:flex;
}
.flex-container {
width:600px;
border: 1px solid red;
padding: 1.6rem;
margin: 1.6rem;
}
.flex-container > * + * {
margin-left: 2.5rem;
}
label {
margin-bottom: 5px;
font-size: 1.8rem;
color:white;
}
.form-control {
flex-grow:1;
height: 50px;
padding: 0.6rem 12px;
border:0 none;
text-align:center;
}
.input-group-btn {
flex-basis: 62px;
flex-shrink:0;
}
.input-group-btn button.btn {
flex-grow: 1;
flex-shrink:0;
border: 0 none
}
.input-group-btn > .btn {
position: relative;
}
.form-control, .input-group-btn .btn {
font-size: 2.4rem;
}
.input-group .input-group-btn > .btn {
border-top: 0 none;
border-bottom: 0 none;
}
.flex-item {
background: white;
height: 50px;
}
.flex-container > * {
flex: 1;
}
.form-control {
min-width: 0;
width: 100%;
}
<div class="flex-container">
<div class="form-group">
<label class="control-label">Start Date</label>
<div class="input-group date date-picker">
<input class="form-control" type="text" placeholder="mm/dd/yy"/>
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label">End Date</label>
<div class="input-group date date-picker">
<input class="form-control" type="text" placeholder="mm/dd/yy" />
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
</div>
<div class="flex-container">
<div class="form-group">
<label class="control-label">Start Date</label>
<input class="form-control" name="start-date" type="text" placeholder="mm/dd/yy" />
</div>
<div class="form-group">
<label class="control-label">End Date</label>
<input class="form-control" name="end-date" type="text" placeholder="mm/dd/yy" />
</div>
</div>
<div class="flex-container">
<input class="form-control" name="start-date" type="text" placeholder="mm/dd/yy" />
<input class="form-control" name="end-date" type="text" placeholder="mm/dd/yy" />
</div>
<div class="flex-container">
<div class="flex-item">asdf</div>
<div class="flex-item">asdf</div>
</div>