Align controls in navbar Bootstrap - html

I am using Bootstrap 3 in my web application , and below html produces the layout depicated in the image
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" [routerLink]="['']" routerLinkActive="active" >Books & NoteBooks</a>
</div>
<ul class="nav navbar-nav">
<li ><a [routerLink]="['']">Home</a></li>
<li *ngFor="let category of categories">
<a [routerLink]="['./acategories' ,category.name , 'products']" routerLinkActive="active">{{category.name}}</a>
</li>
<li><a [routerLink]="['./acart']" routerLinkActive="active">
<span *ngIf="cartCount > 0" class="badge">{{cartCount}}</span>
<span class="glyphicon glyphicon-shopping-cart"> Bag</span></a></li>
<li><a [routerLink]="['./aorders']" routerLinkActive="active">Order Details</a></li>
<li><a [routerLink]="['./about']" routerLinkActive="active">About</a></li>
<li> > > > </li>
</ul>
<form class="form-inline" (ngSubmit)="onSearch()">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
<div class="input-group">
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Item Name">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Search"/>
</form><br>
</div>
Now I would like to have text box and search button vertical aligned middle , any idea what needs to be modified.

You can try with padding-top and padding-bottom. Check out working solution here jsbin
Hope this will help you.

You can try using the .navbar-form class along with the .form-inline class as:
<form class="form-inline navbar-form" role="form" (ngSubmit)="onSearch()">
<div class="form-group">...
After this, maybe you can get rid of the <br> tag after the form closing tag.
Also, if you want to align the Search box and button to the right corner, you can use .navbar-right as well:
<form class="form-inline navbar-form navbar-right" role="form" (ngSubmit)="onSearch()">
<div class="form-group">...

Related

CSS - Moving items around in Navbar

See screenshots for what I am trying to achieve.
https://imgur.com/jaOmFnz
https://imgur.com/aRxile9
The menu list items (My application, Register, Login) I want to move to the far right of the screen. I have tried messing with the margins, float:right, however still cannot get this to work.
The container div spans the full width. Would I need to amend this div?
I've created a codeped to illustrate this
https://codepen.io/jquerypain121/pen/OJNaWpa
<html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log in - PhotoUploaderForm</title>
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-white border-bottom box-shadow mb-3">
<div class="container">
<img src="https://lh3.googleusercontent.com/proxy/HQAE10KQ0NmS9htB5BKSoN24jWvyaizAKwhGy8hNVVsCbFUubvDdLSsYB8xWbN3JUDzDuAzw0OxKO5QZyL_XPqitq1wcSYaMVJ35_oC48c4FKZYykJUoucS-LJT1" width="200" title="title" alt="additional title">
<a class="navbar-brand" href="/">My Application</a>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class=" moveright nav navbar-nav">
<a class="navbar-brand" href="/">My Application</a>
<li class="nav-item">
<a class="nav-link text-dark" id="register" href="/Identity/Account/Register">Register</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" id="login" href="/Identity/Account/Login">Login</a>
</li>
</ul>
<ul class="navbar-nav flex-grow-1">
</ul>
</div>
</div>
</nav>
</header>
<div class="container-fluid">
<main role="main" class="pb-3">
<h1>Log in</h1>
<div class="row">
<div class="col-md-4">
<section>
<form id="account" method="post" action="/Identity/Account/Login" novalidate="novalidate">
<hr>
<div class="text-danger validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
</ul></div>
<div class="form-group">
<label for="Input_Email">Email</label>
<input class="form-control" type="email" data-val="true" data-val-email="The Email field is not a valid e-mail address." data-val-required="The Email field is required." id="Input_Email" name="Input.Email" value="">
<span class="text-danger field-validation-valid" data-valmsg-for="Input.Email" data-valmsg-replace="true"></span>
</div>
<div class="form-group">
<label for="Input_Password">Password</label>
<input class="form-control" type="password" data-val="true" data-val-required="The Password field is required." id="Input_Password" name="Input.Password">
<span class="text-danger field-validation-valid" data-valmsg-for="Input.Password" data-valmsg-replace="true"></span>
</div>
<div class="form-group">
<div class="checkbox">
<label for="Input_RememberMe">
<input type="checkbox" data-val="true" data-val-required="The Remember me? field is required." id="Input_RememberMe" name="Input.RememberMe" value="true">
Remember me?
</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" formaction="/Identity/Account/Login?returnUrl=%2F">Log in</button>
<input type="hidden" id="ReturnUrl" name="ReturnUrl" value="/">
</div>
<div class="form-group">
<p>
Register as a new user
</p>
</div>
<input name="__RequestVerificationToken" type="hidden" value="CfDJ8PEcG7qoomVJk-wiZaqy0p6b5tfvXZTuVH-9YakoOKQQf8mWfBn4MYD7BCb3YKL_NmEz_Ru57zD8PV8Tq_6ea5WApccwrpwYrOkBdu7Qu9Z6NMycGCHqDTI35Ci1mPMVQSqyQ47sNdvfhZhfkMSx_DQ"><input name="Input.RememberMe" type="hidden" value="false"></form>
</section>
</div>
<div class="col-md-6 col-md-offset-2">
</div>
</div>
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
<p style="float:left;color: white;">© 2020 - Leicestershire Health Informatics Service -</p>
<a style="float:right; margin-right: 10px;" href="/Home/Privacy">Privacy</a>
<a style="float:right;margin-right: 10px;" href="/Home/Information">Info</a>
<a style="float:right;margin-right: 10px;" href="/Home/TermsAndConditions">T&C</a>
</div>
</footer>
</body></html>
Any help would be appreciated, thanks
you don't need to customize the code. Bootstrap has it's own design which you want to achieve. For your reference https://getbootstrap.com/docs/4.5/components/navbar/
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand">
<img src="https://getbootstrap.com/docs/4.5/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top">
My Application
</a>
<div class="form-inline">
<a class="nav-link text-dark" href="">My Application</a>
<a class="nav-link text-dark" id="register" href="/Identity/Account/Register">Register</a>
<a class="nav-link text-dark" id="login" href="/Identity/Account/Login">Login</a>
</div>
</nav>
Instead of writing moveright in your ul class list, write ml-auto. This should move the list to the right.
Make the width of the nav 100%
and then make the ul float: right;
Hope it will work for you

How to ensure Bootstrap button stays in-line with form field within the same column?

Supposedly a rather simple question, but I would appreciate some tips all the same.
I have the following Bootstrap html:
<div class="col-xs-6 col-md-3">
<div class="form-group">
<input autocomplete="off" autofocus="" class="form-control" name="Quantity" placeholder="Quantity required" type="text" id="quantity">
</div>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" id="touch" type="button" data-toggle="dropdown">grams
<span class="caret"></span></button>
<ul class="dropdown-menu" id="menu">
<li>milligrams</li>
<li>grams</li>
<li>kilograms</li>
</ul>
</div>
</div>
However, currently as shown here: http://www.bootply.com/xlkInfMjJo
the button always seems to sit below the input field. Is there a way to get around this and ensure the button stays in-line with the form field within the same column?
Kind Regards,
Yes, this can be achieved by having additional columns for the button and input field, which needs to be wrapped in a .row
So, you only need to change from:
<div class="col-xs-6 col-md-3">
<div class="form-group">
<input autocomplete="off" autofocus="" class="form-control" name="Quantity" placeholder="Quantity required" type="text" id="quantity">
</div>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" id="touch" type="button" data-toggle="dropdown">grams
<span class="caret"></span></button>
<ul class="dropdown-menu" id="menu">
<li>milligrams</li>
<li>grams</li>
<li>kilograms</li>
</ul>
</div>
</div>
To:
<div class="col-xs-6 col-md-3">
<div class="row">
<div class="form-group col-xs-8">
<input autocomplete="off" autofocus="" class="form-control" name="Quantity" placeholder="Quantity required" type="text" id="quantity">
</div>
<div class="dropdown col-xs-4">
<button class="btn btn-primary dropdown-toggle" id="touch" type="button" data-toggle="dropdown">grams
<span class="caret"></span></button>
<ul class="dropdown-menu" id="menu">
<li>milligrams</li>
<li>grams</li>
<li>kilograms</li>
</ul>
</div>
</div>
</div>
This way, the input field will always take 8 units of the width, whereas the button will take 4 - using the default Bootstrap grid system (12 total units).
Would you want to change this ratio, change the .col-xs-* classes newly inserted to your preferred values.
You can also view these changes in this Bootply snippet: http://www.bootply.com/ufUHQgp9bj

How to add a search box with icon to the navbar using materialize css?

I want to embed a simple input search box. I tried to use code like in bootstrap, but I can't make it to work. I have no clue how to do it.
I have this bootstrap code:
<div class="col-sm-3 col-md-3 pull-right">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search"
name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
</div>
Reference: How to add a search box
I have found that : https://ampersandacademy.com/tutorials/materialize-css/navbar-with-autocomplete-search-box
You have to add a div element in the li element of your navbar ul list.
<nav class="white">
<div class="nav-wrapper">
Logo
<ul class="hide-on-med-and-down right">
<li>
<div class="center row">
<div class="col s12 " >
<div class="row" id="topbarsearch">
<div class="input-field col s6 s12 red-text">
<i class="red-text material-icons prefix">search</i>
<input type="text" placeholder="search" id="autocomplete-input" class="autocomplete red-text" >
</div>
</div>
</div>
</div>
</li>
<li>Sass</li>
<li>Components</li>
<li>JavaScript</li>
</ul>
</div>
</nav>
Or this way:
<nav class="blue">
<div class="nav-wrapper">
<i class="material-icons">cloud</i>Logon
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li>
<form>
<div class="input-field">
<input id="search" type="search" required>
<label class="label-icon" for="search"><i class="material-icons">search</i></label>
<i class="material-icons">close</i>
</div>
</form>
</li>
<li>Sass</li>
<li>Components</li>
<li>JavaScript</li>
</ul>
</div>
</nav>

How to align three items in same row with Bootstrap 3?

I'm trying to align three items in the same row but am having problems doing this in Bootstrap 3. Here is how they look now:
But I want them to be aligned in the same row (horizontally) and not be aligned vertically.
I have a fiddle here: http://jsfiddle.net/DTcHh/2132/
The relevant code is:
<div class="pull-right">
<form action="#" method="post" class="form-horizontal">
<div class="control-label">
<div class="control">
Pull right on a form will only work if the form has a specific width. In most cases you don't want to use that, but use the grid system.
You should use .input-group to add buttons to an input and show them on the same line.
You're not using labels, so there is no use for .form-horizontal.
See the fiddle
<div class="row">
<div class="col-sm-3 col-md-3">
<ul class="nav nav-pills">
<li class="active">Pill1
</li>
<li class=""><span id="pendingcount">Pill2</span>
</li>
</ul>
</div>
<div class="col-sm-6 col-sm-push-3">
<form action="#" method="post">
<input type="hidden" value="Date" name="filtertype" class="dropdown-field">
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Date <span class="caret"></span></button>
<ul class="dropdown-menu">
<li> Date</li>
<li> Requestor</li>
<li> Classification</li>
<li> Destination</li>
<li> Description</li>
<li> File Name</li>
<li> Extracted Text</li>
<li> Extracted Keywords</li>
<li> Status</li>
<li> Scan Code</li>
</ul>
</span>
<input type="text" name="filterterm" value="" class="form-control">
<span class="input-group-btn">
<button type="submit" class="btn btn-default "> <i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</form>
</div>
</div>

Center form in dropdown Bootstrap?

I have a dropdown in bootstrap, but I don't know how to center a form I have within it.
Here is my code;
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<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>
<a class="brand" href="#">Testing, 123</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><i class="icon-home icon-white"></i> Home</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<div class="dropdown-menu">
<form accept-charset="UTF-8" action="/sessions" method="post">
<fieldset class='textbox login'>
<label id='js-username'>
<span>Username</span>
<input autocomplete="on" id="username" name="username" type="text" size="20px"/>
</label>
<label id='password'>
<span>Password</span>
<input id="userpassword" name="userpassword" type="password" />
</label>
</fieldset>
<fieldset class='subchk'>
<input name="commit" type="submit" value="Log In" />
</fieldset>
</form>
</div>
</li>
</ul>
<form class="navbar-search pull-right" action="">
<input type="text" class="search-query span2" placeholder="Search">
</form>
</div><!-- /.nav-collapse -->
</div><!-- /.container -->
</div><!-- /.navbar-inner -->
</div><!-- /.navbar -->
I have adjusted the width of the dropdown in the css to fit my form, I just can't work out how to center the form within the dropdown.
Without seeing your CSS it's hard to say for sure that this will work, but try this:
.dropdown-menu form {
width: *insert form width here in pixels*;
margin: 0 auto;
}
This answer assumes that the li with the class dropdown is bigger horizontally than your form, and you are trying to center the form within it. To center something horizontally using this method it must have a fixed width, and the width must be smaller than the parent element (in this case the li with the class dropdown).
Edited to add: I didn't realize how old this question was until after I answered it..
Just create a class with some padding and add it to your form tag, like so:
CSS
.wrap {
padding:15px;
}
HTML
<form class="wrap" accept-charset="UTF-8" action="/sessions" method="post">...</form>
Demo: http://jsfiddle.net/a52UY/
use center tag it might be help to you
<center> </center>
<div class="dropdown-menu">
<center>
<form accept-charset="UTF-8" action="/sessions" method="post">
.......
</form>
</center>