<p>Basically, this is just a simple fixed-fluid layout implementation. The problem for implementation with form elements is that, an input element cannot be set as a full width element automatically without <code>width</code> property even when we set it as a block element.</p> <p>They are different with <code>div</code>- s …</p> <p>So here I use a separate <code><div></code> to handle the fixed width value for the button. We are going to make the search field to be expandable but not for the search button. Here's the basic concept with simplified <abbr title="Hyper Text Markup Language">HTML</abbr> markup and simplified <abbr title="Cascade Style Sheet">CSS</abbr> code:</p> <h3>HTML Markup</h3> <pre> <code><form>
<p>Basically, this is just a simple fixed-fluid layout implementation. The problem for implementation with form elements is that, an input element cannot be set as a full width element automatically without <code>width</code> property even when we set it as a block element.</p><p>They are different with <code>div</code>-s …</p><p>So here I use a separate <code><div></code> to handle the fixed width value for the button. We are going to make the search field to be expandable but not for the search button. Here's the basic concept with simplified <abbr title="Hyper Text Markup Language">HTML</abbr> markup and simplified <abbr title="Cascade Style Sheet">CSS</abbr> code:</p><h3>HTML Markup</h3><pre><code><form>
<div>
<input type="text">
<input type="submit" value="Search">
</div>
</form></code></pre><h3>CSS</h3><pre><code><span class="cm">/*
First, we set the `box-sizing` value as `border-box` so ...
we could easily expand this element to 100% width without worrying about
the `padding` and `border-width` calculation.
*/</span>
form input {box-sizing:border-box}
<span class="cm">/*
create the room for the button using `margin`
*/</span>
form > div {
position:relative;
margin-right:110px; <span class="cm">/* same with `button width` + `button distance from search field` */</span>
}
<span class="cm">/*
SEARCH FIELD: the `box-sizing` value for this element already set as `border-box`
and the right margin value also already set with the correct value
to make the room for the button, so now we could safely
expand this element to 100% width!
*/</span>
form input[type="text"] {
display:block;
width:100%;
}
<span class="cm">/*
SEARCH BUTTON: the last step is to make the button pushed to the right by using absolute position
(you could use `float:right` for this but you have to put the button markup before the text field,
so if the CSS is disabled, destroyed or whatever, the search box appearance will looks ugly because
the search button appears before the search field!!!)
*/</span>
form input[type="button"] {
display:block;
width:100px; <span class="cm">/* this is the `button width` */</span>
position:absolute;
top:0;
left:100%; <span class="cm">/* push to the right! */</span>
margin-left:10px; <span class="cm">/* this is the `button distance from search field` */</span>
}</code></pre>
<h3>Demo</h3>
<p>Now you can put this search box inside your fluid sidebar, your fluid column, your fluid header, your fluid article, etc… without worrying if the button will shifted or moved underneath the search field awkwardly because of the limited container width…</p>
<div class="col-group">
<div>
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
</div>
<div class="col-group">
<div class="col-left">
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
<div class="col-right">
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
</div>
<div class="col-group">
<div class="col-left col-group">
<div class="col-left">
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
<div class="col-right">
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
</div>
<div class="col-right col-group">
<div class="col-left">
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
<div class="col-right visible-outline">
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field" spellcheck="false">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
</div>
</div>
</div>
/* Ignore this! */
/* Ignore this! */
@import url('http://fonts.googleapis.com/css?family=Open+Sans:400,700');
* {
margin:0;
padding:0;
}
body {
background-color:#EDEDE8;
font:normal normal 16px/1.4 "Open Sans",Segoe,"Segoe UI",Frutiger,"Frutiger Linotype","DejaVu Sans","Helvetica Neue",Arial,Sans-Serif;
color:#333;
text-shadow:0 1px 0 white;
padding:10px 0 0 10px;
}
abbr {
border-bottom:1px solid #aaa;
font-weight:bold;
background-color:#e5e5e5;
padding:0 3px;
cursor:help;
}
p,
pre {margin:0 10px 10px 0}
code {
font-family:Consolas,"Andale Mono WT","Andale Mono","Lucida Console","Lucida Sans Typewriter","DejaVu Sans Mono","Bitstream Vera Sans Mono","Liberation Mono","Nimbus Mono L",Monaco,"Courier New",Courier,Monospace;
font-size:14px;
}
pre {
line-height:1.2;
background-color:white;
padding:1em;
overflow:auto;
border-radius:3px;
box-shadow:0 1px 1px rgba(0,0,0,.1);
}
.cm {
color:#999;
font-style:italic;
}
h3 {
font-weight:bold;
margin:20px 10px 10px 0;
}
.col-group {overflow:hidden}
.col-left {
width:50%;
float:left;
}
.col-right {
width:50%;
float:right;
}
@media (max-width:600px) {
.col-left,
.col-right {
float:none;
display:block;
width:auto;
}
}
/*
==========================================================================
CSS for Fluid Width Search Box
==========================================================================
<form class="form-search">
<div class="form-search-wrapper">
<input type="text" class="form-search-field">
<input type="submit" class="form-search-submit" value="Search">
</div>
</form>
==========================================================================
==========================================================================
*/
button::focus-inner,
input::focus-inner {
margin:0;
padding:0;
border:none;
outline:none;
}
.form-search {margin:0 10px 10px 0}
.form-search-field,
.form-search-submit {
display:block;
background-color:white;
color:#666;
font:inherit;
line-height:normal;
border:1px solid #ccc;
border-top-color:#aaa;
padding:10px;
outline:none;
box-sizing:border-box;
text-shadow:none;
text-align:left;
}
.form-search-wrapper {
position:relative;
margin-right:125px;
}
.form-search-field {
width:100%;
box-shadow:inset 0 1px 1px rgba(0,0,0,.1);
}
.form-search-submit {
width:115px;
padding-right:0;
padding-left:40px;
background:#4c8c00 url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH3QwPCzE0FFtE4AAAAQlJREFUOMuVkr1KxFAUhOekUrAR/CksfActRX0BS0HEF7BbsBQLkbW2ULBSe8VCWB9EEBsFwdLOdQVxYT+biVzCJt4MBHLnzJmbkzOhBMCcpF1JG5IWTb9J6kk6j4h31QHYBgbUYwDs1DVvAiMLb4E1YNrPKnDj2gjYqjbPAB8WHDZ84YE1fY/6Vzhyoad/ANxZe5ySDybXMwxWrH1MyU+TUxkGE9Z+AyFJhdohJJH2FZJe/b6cYbBkk5eIoDS4d7GTYVBqrtO55pM17jXM37FmCMzmBGnSPy0NUokroBgX5a+GKA8r58txJgvACfAM/Fj4BOw7sRcVk9NWOwQK31yir7awyZnD1P0F9SaVT76pzq4AAAAASUVORK5CYII=') no-repeat 15px 50%;
border-color:#467903 #467903 #243e03;
color:white;
position:absolute;
top:0;
left:100%;
margin-left:10px;
cursor:pointer;
box-shadow:1px 1px 1px rgba(0,0,0,.2);
}
.form-search-submit:focus,
.form-search-submit:hover {
background-color:#488100;
border-bottom-color:#1c3103;
}