bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

input group in navbar in Chrome

Open erikverstegen opened this issue 13 years ago • 21 comments

When you have an input-group (I've only tested it with a button) inside a navbar the form doesn't align and makes the navbar height way longer.

erikverstegen avatar Aug 20 '13 18:08 erikverstegen

It works, except the width of the input goes crazy (hence the style="width: 200px;" hack): http://jsfiddle.net/9Z4MN/3/

cvrebert avatar Aug 20 '13 18:08 cvrebert

Actually, the docs also cover the need to set an explicit width, so then this is just a matter of needing to use the correct markup; see jsFiddle for working example.

cvrebert avatar Aug 22 '13 06:08 cvrebert

My apologies, the input width thing does seem like a legit bug.

cvrebert avatar Aug 23 '13 17:08 cvrebert

Testcase: http://jsfiddle.net/Y9tqk/ If you uncomment the .input-group & .input-group-addon, then it's fine on mobile, but the input is crazy-wide on desktop screens. If you leave it commented, then it works fine everywhere.

cvrebert avatar Aug 23 '13 17:08 cvrebert

I can't style input width within a input-group; automatic size is fine for others surrounded controls but rarely useful for input one. The problem happens when you are text addon before and text addon after.

gitmar avatar Aug 24 '13 20:08 gitmar

Also applies to plain .form-inline; see #10294.

cvrebert avatar Aug 29 '13 23:08 cvrebert

This bug is preventing us from moving up from Bootstrap 2.3.2 on our project.

gsmethells avatar Sep 04 '13 16:09 gsmethells

It had taken me hours to look for the right class to prevent the input field in navbar from being crazy wide before I got it's a bug. Will go with the style="width: 200px;" hack. Thanks.

johnwangwjq avatar Oct 07 '13 04:10 johnwangwjq

Filing this as a Chrome bug: https://code.google.com/p/chromium/issues/detail?id=309483.

The gist is that an element with display: table; that's placed within a parent that has display: inline-block; occupies 100% of the available space when no pixel-width is set. Note that a % width doesn't work either. Once you add a pixel-based width to the .input-group, everything gets (no pun intended) back in line.

mdo avatar Oct 20 '13 22:10 mdo

I believe I am also seeing the same bug in Safari 7.0 on OS X Mavericks.

servelink avatar Nov 02 '13 19:11 servelink

Here's a minimal fix

Add class .navbar-input-group to the form

<form class="navbar-form navbar-left navbar-input-group" role="search">
  <div class="form-group">
    <input type="text" class="form-control" placeholder="Search for awesome stuff">
  </div>
  <button type="submit" class="btn btn-default">Search</button>
</form>

Then add additional CSS (place in media query if necessary):

.navbar-input-group {
  font-size: 0px; /*removes whitespace between button and input*/
}

.navbar-input-group .form-control {
  border-top-right-radius: 0px;
  border-bottom-right-radius: 0px;
}
.navbar-input-group .btn {
  border-top-left-radius: 0px;
  border-bottom-left-radius: 0px;
  border-left: 0px;
}

For purposes of clarity, I am targeting descendant elements in the CSS. This is not the most efficient way to target CSS elements. If you decide to use this, consider giving the input and button unique class names and targeting them without any descendant selectors in your CSS (read: http://csswizardry.com/2011/09/writing-efficient-css-selectors/)

michellelaralin avatar Nov 10 '13 19:11 michellelaralin

célzott leszármazott elemek a CSS. Ez nem a leghatékonyabb módja annak, hogy cél -hogy ezt fontolóra a bemeneti és a gombok egyedi osztály nevét,

ghost avatar Nov 10 '13 21:11 ghost

Safari 7.0 (9537.71) - same problem Chrome 31.0.1650.57 - same problem Firefox 25 and 25.0.1 - there it's OK

richardriman avatar Nov 26 '13 23:11 richardriman

Also applies to IE 11

meywd avatar Mar 02 '14 13:03 meywd

An simple fix for this is targeting .input-group-btn and input-group-addon within .navbar-form with a auto width. See below:

.navbar-form .input-group-btn, .navbar-form .input-group-addon { width: auto; }

ghost avatar Mar 07 '14 07:03 ghost

@ntkk72 Your fix is perfect! @mdo Any chance this will be included in Bootstrap? Does a new issue need to be opened to reference this solution?

Panman82 avatar Mar 14 '14 21:03 Panman82

Thanks @ntkk72 your fix has saved my sanity!

YorkshireKev avatar Mar 22 '14 21:03 YorkshireKev

The same, thanks @ntkk72, your fix resolved my problem!

X13454 avatar Mar 25 '14 17:03 X13454

If there is still a bug in the latest master, yes, please open a new issue. Include a link to this one and a new test case (preferably a JS Bin).

mdo avatar Mar 26 '14 05:03 mdo

thanks @ntkk72,

To make sure inputs are taking 100% width when collapsed, I put ntkk72 css correction within @media (min-width:768px;){}

Charlicus avatar May 20 '14 09:05 Charlicus