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>
Related
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">...
I have limited website coding experience. I'm trying to implement bootstrap into my site, specifically by creating a navbar with it. It is working great except for when I lick the login button for the dropdown menu, the menu appears far too wide for the content. I used a css stylesheet to align the username and password forms to the right of the dropdown menu but there is still too much whitespace to the left of the forms.
For instance, I would much rather it trim down to the beginning of the 'newsletters' button.
Site can be found here: my_test_site
Code:
<li>Login <b class = "caret"></b>
<div class = "dropdown-menu dropdown-menu-right">
<div class="container">
<form class="form-inline" role="form" id="username">
<div class="form-group">
<label for="username">Username:</label>
<input type="username" class="form-control" id="email" placeholder="username">
</div>
<div class="form-group" id="password">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
</li>
</ul>
The Class dropdown-menu has a min-width attribute.
min-width: 10rem;.
just override it with.
min-width: 1rem;
Here is a solution to the question of How to fix bootstrap menu into contents?
It doesnt use the single line format and reduce the whitespace specifically as requested, and heres why:
Even if you reduced the width of the dropdown panel containing the signin form , the form wasn't rendering properly in mobile view, e.g. you will see what I mean if you reduce the browser down to mobile size in your my_test_site demo, and then try to use the form .
How does my version work?
By changing bootstrap in the minimum way, my version works in both full width and mobile (as far I have tested anyway)
Also, I saw your CSS style rules and removed them - so there is really only bootstrap CSS + plus this inline style rule style="padding: 10px;" on the div wrapping your form
So basically
remove your style rules
Drop in the below code
Change the content of the code
And you should be go to go!
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<!-- Begin custom dropdown menu -->
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
<!-- begin custom form -->
<div style="padding: 10px;"
<form class="form-inline" role="form" id="username">
<div class="form-group">
<label for="username">Username:</label>
<input type="username" class="form-control" id="email"
placeholder="username">
</div>
<div class="form-group" id="password">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<!-- end custom form -->
</li>
</ul>
</li>
<!-- Begin custom dropdown menu -->
</ul>
</div><!-- /.navbar-collapse -->
Here is a working demo - http://jsbin.com/lineketuru/1/edit?html,output
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>
Using Bootstrap 3, I am trying to align adjacent input elements with my label which is intended to be grouped with a checkbox. At the moment, the checkbox and label are displayed a few pixels below the search query box and button. The brand name also appears to be a few pixels higher.
On Bootply: http://www.bootply.com/6tJSBqZ2d5
<div class="container row navbar navbar-inverse navbar-fixed-top">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand Name</a>
</div>
<form class="navbar-form navbar-right" id="search-form" method="get" name="search-form">
<div class="input-append">
<input class="form-control" id="query" name="query" placeholder="Search..." value=""> <button class="btn btn-info" type="submit"><span class="glyphicon glyphicon-search"></span></button>
<div class="checkbox">
<h3><span class="label label-default">Refresh
<input type="checkbox"></span></h3>
</div>
</div>
</form>
</div>
What is the proper way to align all elements and have them properly spaced?
The h3 is adding margin-top and margin-bottom, and the checkbox element that you have is 8px shorter than the other elements in the header.
So if you add the h3-align class as shown below to the h3 then it will be aligned:
CSS:
.h3-align {
margin-top: -4px;
margin-bottom: 0px;
}
HTML
<h3 class="h3-align">
<span class="label label-default">Refresh
<input type="checkbox">
</span>
</h3>
Bootply example
In twitter bootstrap 3 i would like to add a buttongroup in the navbar, but it seems to break the navbar since it creates linebreaks:
<li>
<form class="navbar-form form-inline" >
<div class="input-group">
<input id="filter" class="form-control input-sm" type="text" placeholder="Filter" />
<span class="input-group-btn">
<button id="clearfilter" type="button" class="btn btn-sm btn-default">Clear</button>
</span>
</div>
</form>
</li>
how can i avoid the linebreak in the navbar?
Maybe you don't need the to put the form inside a list item:
<!-- Start Of Example -->
<form class="navbar-form form-inline">
<div class="input-group">
<input id="filter" class="form-control input-sm" type="text" placeholder="Filter" />
<span class="input-group-btn">
<button id="clearfilter" type="button" class="btn btn-sm btn-default">Clear</button>
</span>
</div>
</form>
<!-- End Of Example -->
JS Fiddle Example
Update: another method (you could also use navbar-right to align the ul block to the right)
<!-- Start Of Example -->
<ul class="nav navbar-nav">
<li>
<div class="navbar-form form-inline" role="form">
<div class="form-group">
<input id="filter" class="form-control input-sm" type="text" placeholder="Filter" />
</div>
<div class="form-group">
<button id="clearfilter" type="button" class="btn btn-sm btn-default">Clear</button>
</div>
</div>
</li>
<li>
<li>Action</li>
</li>
</ul>
<!-- End Of Example -->
Example 2