Right now I have a navigation bar that looks like:
http://bootply.com/78239
I want to maximize the width of the "search" text-input, without creating line-breaks (i.e., that the "Clear" link will be tight with the "About" link).
I only have basic experience with css and web-design. I read something about "overflow: hidden" tricks, but I don't understand how to use it when there are more elements to the right of the targeted element.
Thanks
EDIT:
A partial solution can be to set the width "manually" for each case, like in http://bootply.com/78247 :
#media (max-width: 767px) {
#searchbar > .navbar-form {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
#searchbar > .navbar-form {
width: 205px;
}
}
#media (min-width: 992px) and (max-width: 1199px) {
#searchbar > .navbar-form {
width: 425px;
}
}
#media (min-width: 1200px) {
#searchbar > .navbar-form {
width: 625px;
}
}
but this solution will not work when the menu's texts are "dynamic" (for example, contain "Hello username").
I suppose it is not a big issue if you assume that there is a limit on the menu's texts' widths - it's just annoying to calculate/test those widths manually.
I'm just curious to know if there's a neat way to do it automatically.
For Bootstrap version 3.2 and up you should also set the display:table; for the input-group and set the width to 1% for the input-group-addon.
<div style="display:table;" class="input-group">
<span style="width: 1%;" class="input-group-addon"><span class="glyphicon glyphicon-search"></span></span>
<input type="text" autofocus="autofocus" autocomplete="off" placeholder="Search Here" name="search" style="" class="form-control">
</div>
Demo Bootstrap version 3.2+: http://www.bootply.com/t7O3HSGlbc
--
If you allow changing the position of your navbar elements? I don't understand "without creating line-breaks (i.e., that the "Clear" link will be tight with the "About" link)." Try this: http://bootply.com/78374.
What i did:
Drop the float left of the form (by dropping the navbar-left class)
Give other navbar elements a right float (the navbar-right class)
Set display of the form-group to inline (style="display:inline")
Change the position of the elements (the right floated first)
Related question:
Expand div to max width when float:left is set
html:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">My Project</a>
</div>
<div class="navbar-collapse collapse" id="searchbar">
<ul class="nav navbar-nav navbar-right">
<li>About</li>
<li id="userPage">
<i class="icon-user"></i> My Page
</li>
<li>Logout</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Clear</li>
</ul>
<form class="navbar-form">
<div class="form-group" style="display:inline;">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-search"></span></span>
<input class="form-control" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus" type="text">
</div>
</div>
</form>
</div><!--/.nav-collapse -->
</div>
</div>
Two things worked for me here. Adding Orens media queries, and also adding a display: inline to that searchbar form group:
<li id="searchbar">
<form id="search_form" class="navbar-form navbar-left navbar-input-group " role="search">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">All <span class="caret"></span>
</button>
</div>
<div class="form-group">
<input name="search_input" type="text" class="form-control typeahead" placeholder="Search for items or shops" autofocus="autofocus">
</div>
<span class="input-group-btn">
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
</button>
</span>
</div>
</form>
</li>
With the css:
#search_form > .input-group > .form-group {
display: inline;
}
Related
I have a problem when I use inline-form the input text does not take all the space.
I am aware of that information, but I am a bootstrap beginner.
Requires custom widths Inputs, selects, and textareas are 100% wide by
default in Bootstrap. To use the inline form, you'll have to set a
width on the form controls used within. The default width of 100% as
all form elements gets when they got the class form-control didn't
apply if you use the form-inline class on your form.
Cordially
<div class="panel panel-primary">
<div class="panel-heading"><h4>Search Options</h4></div>
<div class="panel-body">
<form class="form-inline">
<div class="form-group">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
Account ID <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Account ID</li>
<li>Company Name</li>
<li>Account Type</li>
<li role="separator" class="divider"></li>
<li>Marketplaces</li>
</ul>
</div>
</div>
<div class="form-group">
<input class="form-control" type="text"
value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-default"> Filtrer </button>
</div>
</form>
</div>
</div>
According to Docs
May require custom widths
Inputs and selects have width: 100%; applied by default in Bootstrap.
Within inline forms, we reset that to width: auto; so multiple
controls can reside on the same line. Depending on your layout,
additional custom widths may be required.
EDIT
as per your comment:
the input text take the rest of space. I want inline all the elements
in a single row and if a space is left the input text should take it
use flexbox
/* !important ONLY USED FOR SNIPPET */
.form-inline {
display: flex
}
.flex {
flex: 1;
display: flex !important
}
.flex input {
flex: 1 !important
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="panel panel-primary">
<div class="panel-heading">
<h4>Search Options</h4>
</div>
<div class="panel-body">
<form class="form-inline">
<div class="form-group">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Account ID <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Account ID</li>
<li>Company Name</li>
<li>Account Type</li>
<li role="separator" class="divider"></li>
<li>Marketplaces</li>
</ul>
</div>
</div>
<div class="form-group flex">
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-default"> Filtrer </button>
</div>
</form>
</div>
</div>
Add a container as a 'context' in your markup and then use it to override your css in this specific context :
<div class="special-form">
<!-- form -->
</div>
CSS
.special-form .panel .form-control {
width: 100%;
}
I am developing a site, where I have Login div as part of header in Desktop view. Where as the same div has to be appear in Mobile menu along with existing menu items as shown below:
So, how to implement this as part of mobile menu item (Without using 2 Divs for hide/show) using Bootstrap?
You could use the navbar class for your header. And then bootstrap will automatically behave that way. Otherwise you should use the media query.
Or you could use the visible-xs, visible-sm, etc. bootstrap classes (with mulitple div's), to handle what is viewed on which device.
first of all this is no javascript / jquery question.
What you wannt to do is explained here
See how aspects of the Bootstrap grid system work across multiple devices with a handy table.
bootstrap itself does the job just read that doc
I Think You Have Too Use .col-md class from bootstrap.
Give Class OF menu div as col-md-4 and in login and content div has col-md-8.
For Example,
<div class="row">
<div class="menu col-md-4"></div>
<div class="login col-md-8"></div>
</div>
Just Like This...
If You Are Don't familiar with Bootstrap. Then First Read Out The Documentation That Will Suggested By Burak Topal . So You are understand that what this class will actually do.
Might This Will Helpful.
I found the solution for this without using media queries. We need to place both top and left navbars inside ".navbar-collapse" class.
I have used a custom class "navbar-fixed-left" to make the left navbar.
.navbar-fixed-left {
margin-top: 47px;
left: 0px;
width: 140px;
position: fixed;
border-radius: 0;
height: 100%;
}
.navbar-fixed-left .navbar-nav > li {
float: none; /* Cancel default li float: left */
width: 139px;
}
.navbar-fixed-left + .container {
padding-left: 160px;
}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="User Name">
<input type="text" class="form-control" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Login</button>
</form>
<div class="navbar-inverse navbar-fixed-left">
<ul class="nav navbar-nav">
<li>Menu 1</li>
<li>Menu 2</li>
</ul>
</div>
</div>
</div>
</nav>
<div class="container">
<h3>Content goes here...</h3>
</div>
With the following code, on a "middle screen", the result is OK.
But on a small screen (smartphones), it is not.
I wish the input and the submit button (magnifying glass) are aligned on the same line.
How I can do that?
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Diko Responsive</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<form class="navbar-form navbar-right" action="index.php" method="get">
<div class="form-group" >
<input id="terme" name="terme" placeholder="Veuillez saisir un terme" class="form-control input-xs" type="search">
<button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-search"></span></button>
</div>
</form>
</div>
</div>
</nav>
Thanks.
EDIT: I added this CSS file after the advices of #NiklasMH
#media (max-width : 768px){
.form-group input {
width: calc(70% - 32.5px);
}
.form-group button {
width: 40px;
}
}
But as you can see, both are still not aligned.
You almost there. You only forgot to call class=input-group
You no need to add another media queries there.
HTML
<div class="input-group">
<input id="terme" name="terme" placeholder="Veuillez saisir un terme" class="form-control input-xs" type="search">
<span class="input-group-btn">
<button class="btn btn-info" type="button"><span class="glyphicon glyphicon-search"></span></button>
</span>
</div>
Here is the DEMO
I don't know the twitter-bootstrap that good, so this answer is more about what you can do to the CSS.
Bad practice
Some say it's bad practice, but you could eigther use a table to align them on the same row. Then you also can make the left or right column in fixed width like:
td:last-child {
width: 32px;
}
Good practice
Or you can use the calc-value in CSS, which is widly supported now (except in Opera Mini - ref caniuse.com), like:
.form-group input {
width: calc(100% - 44px); /* Minus a little more (4px) than the button-width */
}
.form-group button {
width: 40px;
}
Remember that padding will make the element bigger and force more space, so set box-sizing to border-box (default content-box) to avoid this:
.form-group input, .form-group button {
box-sizing: border-box;
}
JSFIDDLE
.form-group input, .form-group button {
box-sizing: border-box;
}
.form-group input {
width: calc(100% - 44px);
max-width: 160px;
}
.form-group button {
width: 40px;
}
<div class="form-group">
<input placeholder="text"/>
<button>btn</button>
</div>
I'm trying to solve the various issues with Bootstrap input-group placed inside navbar. The formatting http://bootply.com/101777
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<span class="navbar-brand">Game</span>
</div>
<form class="navbar-form navbar-left itg-game">
<div class="form-group itg-first">
<div class="input-group">
<span class="input-group-addon" ng-bind="first.name"></span>
<input type="text" class="form-control" readonly ng-model="first.value">
</div>
</div>
<div class="form-group">
<div class="btn-group itg-action">
<button ng-click="swap()" class="btn btn-default itg-action-btn" ng-bind="text"></button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href ng-click="resetGame()">Reset game</a></li>
</ul>
</div>
</div>
<div class="form-group itg-second">
<div class="input-group">
<input type="text" class="form-control" readonly ng-model="second.value">
<span class="input-group-addon" ng-bind="second.name"></span>
</div>
</div>
<div class="form-group itg-fee">
<div class="input-group">
<input type="text" class="form-control" readonly ng-model="fee">
<span class="input-group-addon">fee</span>
</div>
</div>
</form>
</nav>
</div>
And the styles:
#media (min-width: 768px) {
.itg-game { }
.itg-game .itg-first, .itg-game .itg-second { width: 12em; }
.itg-game .itg-fee { width: 8em; }
.itg-game .itg-action { text-align: center; }
.itg-game .itg-action .itg-action-btn { width: 15em; }
}
There are two issues:
The mobile view (less than 768px) is completely rubbish - lines overlaps the borders of the navbar, controls stick to the borders.
mid-size version is better but for some reason the third input jumps to the third line.
It looks like the input-groups are not compatible with navbars. Am I right?
They work fine with the navbar with a minimal amount of fiddling with the css, but you can't have it set up like you have it because the size matters. Input groups are display:table and 100% width, they need a col-. If you had too many links or links with really long names, your navbar would break down crappily.
DEMO http://jsbin.com/putuki/1/edit
<div class="navbar navbar-default navbar-static-top my-navbar">
<button class="navbar-toggle visible-xs" data-target=".navbar-collapse" data-toggle="collapse" type="button"><span class="sr-only">Toggle navigation</span> <span class="icon-bar"><!--empty--></span> <span class="icon-bar"><!--empty--></span> <span class="icon-bar"><!--empty--></span></button>
<div class="container visible-xs">
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="navbar-collapse collapse" id="mynavcollapse">
<div class="container">
<div class="row">
<form>
<div class="col-sm-2 hidden-xs">
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="col-sm-2">
<div class="input-group">
<input class='form-control' placeholder="Search: (stuff)" type='text'> <span class="input-group-btn"><button class="btn btn-default">Button</button></span>
</div><!-- /input-group -->
</div><!-- /col- -->
<div class="col-sm-2">
<div class="input-group">
<input class='form-control' placeholder="Search: (stuff)" type='text'> <span class="input-group-btn"><button class="btn btn-default">Button</button></span>
</div><!-- /input-group -->
</div><!-- /col- -->
<div class="col-sm-3">
<div class="input-group">
<input class='form-control' placeholder="Search: (stuff)" type='text'> <span class="input-group-btn"><button class="btn btn-default">Button</button></span>
</div><!-- /input-group -->
</div><!-- /col- -->
<div class="col-sm-3">
<div class="input-group">
<input class='form-control' placeholder="Search: (stuff)" type='text'> <span class="input-group-btn"><button class="btn btn-default">Button</button></span>
</div><!-- /input-group -->
</div><!-- /col- -->
</form>
</div>
</div>
</div>
</div>
CSS
.my-navbar .row [class*="col-"] {
margin-top: 10px
}
#mynavcollapse {
clear: both;
padding: 0 0 10px;
background: #eee;
}
#media (min-width: 768px) {
.my-navbar .navbar-brand {
float: none;
display: inline-block;
padding: 7px 0 0 0;
}
.my-navbar .row {
margin-left: -.5%;
margin-right: -.5%;
}
.my-navbar .row [class*="col-"] {
min-height: 1px;
padding-left: .5%;
padding-right: .5%;
padding-top: 10px;
margin-top: 0;
}
}
Here is an image of my problem.
See how the hamburger/menu icon is pushed down to the next line? I want the text to go to the next line instead, keeping the menu button and header text next to eachother. The title text and menu are floated left and right respectively.
This doesn't seem to be a clear problem (since I'm trying to do the opposite), and I can't think how the white space property could be used in this case.
The only thing that works is setting a max width on the title, but that messes up the layout at some screen sizes.
I have no custom css on these elements, just what comes with Bootstrap 3
Markup (basically lifted straight from the new Bootstrap 3 docs):
<div class="navbar navbar-default">
<div class = "navbar-header">
<a class = "navbar-brand" href="<%= request.protocol + request.host_with_port%>/weather"> Weather </a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<form id="search" class="navbar-form navbar-right form-inline" method="get" action="/weather">
<div class="form-group">
<input type="text" placeholder="Search for your city or zip" class="form-control" id = "searchbox" name="search">
</div>
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"/></button>
</form>
</div>
`
Stephen,
Two changes are required to get your desired result.
First, set .navbar-brand padding right to 70px or what you needed.
.navbar-brand {
padding-right:70px;
}
And second, make .navbar-toggle position:absolute, right:0;
.navbar-toggle {
position:absolute;
right:0;
top:0;
}
And you are done! :).
Here is demo: http://jsfiddle.net/sARaY/