I have a very basic single input field with a 'submit' button alongside it. The search button has a fixed width of 104 pixels. Both are wrapped together with total width 50% of the browser viewport. It is my plan to allow the input field to enlarge as the browser window enlarges.
At the moment, for my specific browser window, I am having to fix the width of the input field to spread from the left of the wrapper to the left of the submit button. However, as I resize the window, it (obviously) doesn't adjust accordingly, and hence leaves a white space gap.
I have not found an answer to this question anywhere else. I am well aware that usually a width of 100% with a right padding of 104px will solve this kind of issue with other in-line elements. HOWEVER, the issue here is that the button cannot seem to sit above the padding, and instead moves to a new line.
How may I resolve this? Thanks!
EDIT: Here's what I have so far. Visit jsfiddle.net/nWCT8/ The whole wrapper needs to be centered, and it needs to have majority browser support (although I don't mind if IE6 won't work with it). For this reason, I don't think 'calc' is quite suitable.
For newer browsers that support CSS3, you could use
calc()
:html:
css:
jsfiddle
The chosen answer works fine, however, it's overly complicated. Rewrote the answer to be MUCH simpler:
HTML:
CSS:
View example at:
http://jsfiddle.net/nWCT8/4/
Because you have a fixed height, you could use
absolute
position to achieve this (If you don't require to support IE 6)EDIT update my answer base on your jsfiddle, but I only could test it in current Chrome, Safari and FF right now.
jsfiddle
To get auto enlarging work proper with FF you need to use a wrapper around it and the
input
needs to have a width of100%
. To prevent the padding of theinput
elements to be added to thewidth
the following css rules needs to be use:box-sizing
is supported by: IE 8+, Chrome, Opera 7+, Safari 3+, FirefoxEDIT Styling
input
elements is typically problematic because of theirpadding
andmargin
. To have the result you want to achieve without the css3calc
feature you need to do the following steps:Define the height to the surrounding
.form-wrapper
and set itsposition
torelative
so that this element is responsible for the positionabsolute
of the elements it contains.Wrap a container (
.input-wrapper
) around the theinput
element, defining its position asabsolute
withleft:0px
,top:0px
,bottom:0px
andright:[the width of your button]
that way the wrapper always has a distance of thewidth of the button
to the right side.Set the
width
andheight
of theinput
element to100%
. To prevent the padding of theinput
element to be added to thewidth
you need to set thebox-sizing
toborder-box
.Set the position of the
button
toabsolute
withtop:0px
,bottom:0px
andright:0
and setting the width towidth: [width of your button]