Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put input submit on same line as input box

Tags:

html

css

This is probably simple but I dont know how to do it. Currently with this code the "find" button sits on the line below the input "location" box. How do I get it to sit on the same line to the right like most search boxes work?

HTML

<div class="fieldwrapper">
<input id="field_location" class="field r2" placeholder="Town, City or Postcode" id="Postcode" name="Postcode" type="text" value=""><input type="submit" id="findbutton" value="Find" />
</div>

CSS

field { font-family:arial, sans-serif; border-color: #d9d9d9; border-top:solid 1px #c0c0c0; }
input.field{width:100%}

Link http://jsfiddle.net/VL3Dj/

like image 412
James Willson Avatar asked Oct 12 '12 12:10

James Willson


People also ask

How do you put an input element on the same line as its label?

Using float and overflow attributes: Make a label and style it with float attribute. Now set the label float(position) left or right according to your requirement. This will align your label accordingly. Overflow property for input is used here to clip the overflow part and show the rest.

How do I link a submit button to a form?

To link a submit button to another webpage using HTML Form Tags: Using the HTML Form's Action Attribute, we can link the submit button to a separate page in the HTML Form element. Here, declare/write the “Submit button” within HTML Form Tags and give the File Path inside the HTML form's action property.

How do I put two text on the same line in HTML?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

How do you put a space between two inputs?

HTML Break (<br>) Tag If you want to prevent a line break between two words, use a non-breaking space. If you want to insert a line break, use the HTML break tag, written as <br>. You don't need a closing tag here — just writing <br> adds a line break.


3 Answers

If you want your text box to be 100% width and a button besides it you can do it like this : My Fiddle

<input type="submit"value="Find" style="float: right" />
<div style="overflow: hidden; padding-right: .5em;">
   <input type="text" style="width: 100%;" />
</div>​
like image 183
Mr. Alien Avatar answered Oct 24 '22 23:10

Mr. Alien


............Demo

Hi now add this css

.fieldwrapper{
white-space: nowrap;
}

Live demo

like image 42
Rohit Azad Malik Avatar answered Oct 25 '22 01:10

Rohit Azad Malik


You only need to know the width of the button for it to work. Then you basically give the input a full width and position absolute the button to the right. The padding is so no text sits behind the button:

    <form method="post" action="">
      <input type="text" name="search-str" id="search-str" value=""/>
      <button type="submit">Submit</button>
    </form>

As for the CSS:

form {
  position: relative;
}

input {
  width: 100%;
  padding-right: 40px;
}

button {
  width: 40px;
  position: absolute;
  top: 0;
  right: 0;
}
like image 43
Dan H Avatar answered Oct 25 '22 00:10

Dan H