Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text input box to occupy all the remaining width within parent block?

Tags:

css

block

How do achieve the following:

┌────────────────────parent────────────────────┐ │ label [text-box                   ] [button] │ │ paragraph                                    │ └──────────────────────────────────────────────┘ 
  • label is aligned to the left
  • button is aligned to the right
  • text-box occupies all remaining width within parent
  • paragraph is aligned to the left, must be left-aligned with label too

Both label and button should obey font properties defined elsewhere as maximum as possible. parent is center-aligned within window, and, naturally, can have arbitrary width.

Please advise.

like image 469
user422039 Avatar asked Apr 28 '11 22:04

user422039


People also ask

How do I make input width fit content?

Use the span. text to fit width of text, and let the input have same size with it by position: absolute to the container.

How do you give text the input type width?

The size attribute specifies the visible width, in characters, of an <input> element. Note: The size attribute works with the following input types: text, search, tel, url, email, and password. Tip: To specify the maximum number of characters allowed in the <input> element, use the maxlength attribute.

How do I change the width of a text box?

To resize a Textbox within a Contact Form, click Edit on the subquestion in your Build tab. Go to the Layout tab and adjust the Textbox Width. Within Contact Forms each field will have a different default width. By specifying a larger or smaller value you can increase or decrease the width of the Textbox.

How do you change the width and height of a text box?

To resize a shape, text box, or WordArt, under Drawing Tools, on the Format tab, in the Size group, enter the measurements that you want into the Height and Width boxes.


1 Answers

Updated [Oct 2016]: Flexbox version...

form {    display: flex;  }  form input[type="text"] {    flex: 1;  }
<form>    <label>Name</label>    <input type="text" />    <button>Submit</button>  </form>  <p>Lorem ipsum...</p>

Original answer [Apr 2011]: Table-less CSS version (of table behavior)...

<div id="parent">     <div id="inner">         <label>Name</label>         <span><input id="text" type="text" /></span>         <input id="submit" type="button" value="Submit" />     </div>     <p>some paragraph text</p> </div> 

CSS...

#inner {     display: table;     width: 100%; } label {     display: table-cell; } span {     display: table-cell;     width: 100%;     padding: 0px 10px; } #text {     width: 100%; } #submit {     display: table-cell; } 

Demo: http://jsfiddle.net/wdm954/626B2/4/

like image 106
wdm Avatar answered Oct 06 '22 07:10

wdm