What is the best way to implement input field and button behavior as displayed here:
If you have a border or padding set for your divs, then you've created additional pixels that will prevent your divs from adding up to a 100% width. To fix this, make sure you've added box-sizing: border-box to the div's styles.
Inline elements are built for text and thus they should flow inline with the text, and only be as wide as the text they contain. Thus, you can't set the width of an inline element. Block elements are made to fill all the available width by default and are thus on their own line rather than flowing inline.
An inline element does not start on a new line. An inline element only takes up as much width as necessary. This is a <span> element inside a paragraph.
To apply width, set css property 'display' to either 'block' or 'inline-block'. block: the element will sit in a single line. In such case you may want to set float so links are in the same line; inline-block; the element will have height, width, etc, and multiple elements will sit in the same line (block).
I like the answer of ScottS, but just to have an alternative: you could use table-like behaviour in CSS:
CSS
.formline{
display: table;
}
.txt{
display: table-cell;
width: 100%;
}
input[type=text]{
-moz-box-sizing: border-box; box-sizing: border-box;
width: 100%;
}
HTML
<div class=formline>
<div class=txt>
<input type=text>
</div>
<input type=submit value=submit>
</div>
http://jsfiddle.net/willemvb/VaFSP/
Yes, with some html and css in place that uses some magic between float
and overflow: hidden
, you can see it working in this fiddle.
HTML
<div class="container">
<div>Some Text</div>
<form>
<button>MyButton</button>
<div class="stretcher"><input type="text" /></div>
</form>
</div>
CSS
.stretcher {
overflow: hidden;
}
button {
float: right;
}
input {
width: 100%;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With