Solved

How can I make a horizontal form 100% width when including a button?

Posted on 2014-01-08
5
669 Views
Last Modified: 2014-01-08
I'd like this inline form to be width:100%.  The search button should be a constant width, but the search box should be dynamic.  Any ideas how to do this?
<form class="form-inline" role="form">
  <div class="form-group">
    <label class="sr-only">Search</label>
    <input type="search" class="form-control" placeholder="Search">
  </div>
  <button type="submit" class="btn btn-default">Sign in</button>
</form>

Open in new window

0
Comment
Question by:TrevorTomato
  • 2
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 39766944
The easiest way is to use a table element.  Still haven't seen anything to beat this approach to fixed width elements

http://jsbin.com/uHodibO/1/edit?html,css,output

    <table class="form-table">
      <tr>
        <td class="row1"><label class="sr-only">Search</label></td>
        <td class="row2"><input type="search" class="form-control" placeholder="Search"></td>
      </tr>
    </table>

Open in new window


css:
.form-table {
  width: 100%;
}
.form-control {
  width: 100%;
}
.row1 {
  width: 5%;
}

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 39766945
You mean you want the input box to be 100% width?

Just add

.form-inline input {
    width:100%
}

http://jsfiddle.net/DUE5R/1/
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39766949
You can emulate a table using css only.  Taking your markup:  http://jsbin.com/icEjeKOY/1/edit?html,css,output

.form-inline {
  width: 100%;  
  display: table;
}
.form-group {
  display: table-row;
}
.cell {
  display: table-cell;
}
.form-control {
  width: 100%;
}
.sr-only {
  width: 15%;
}

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 39766977
I'm guessing here that you are probably using Bootstrap which has a class for 100% widths - just add a class of .form-control to the input (if it is the input you want to be 100%) else Rob's solution maybe the way to go.
0
 

Author Closing Comment

by:TrevorTomato
ID: 39767041
Worked great!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on Add method 1 51
Add css and js to MVC Project not in project 9 37
How to change pointer icon to hand icon on mouseover 2 31
Capture logon name 13 73
CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question