It’s funny, I spend so much time avoiding the box model, that when I have to compensate for it, I have to kick the dust off of my brain cells.
In this case, I am trying to style inline input/button elements.
The input has padding/border. The button is just a fixed width (no padding/borders).
Both are inline elements.
See code below.
Questions:
-
Do I need to compensate for the IE box model for the input (even though it is inline)? As you can see, I added the * html hack to the input, but is it necessary?
-
The below input and buttons are fitting inside of a 200px wide container… How can I make the input and button fit exactly into that width (with a little width between the two)?
170px + 24px = 194px
Based on above math, it seems like I could throw a 6px margin-right on the input and call it good! This, of course, does not work cross-browser.
Is there a fudge factor, between (contemporary + IE7/IE8) browsers, with inline elements? It appears that there is, that is why I put only a 2px right margin on the input (basically, I am trying to give some space between the input and the button. It would be nice for the two elements to fit exactly into its parent container).
I am thinking a might be my best option (in other words, just go with the fudge factor, and stop trying to get these inline elements to fit perfectly).
Tips?
Thanks!
Micky
CSS:
#fm_search {
margin: 0;
padding: 0;
}
#fm_search * { vertical-align: middle !important; }
#fm_search label { color: #999 !important; }
#fm_search input {
width: 158px; /* 170px when you add it all up. */
border: 1px solid #999;
margin: 0 2px 0 0; /* Fudge factor */
padding: 5px;
-webkit-box-shadow: 0 0 3px #999;
-moz-box-shadow: 0 0 3px #999;
box-shadow: 0 0 3px #999;
}
* html #fm_search input { width: 170px; } /* Fix IE box model. */
form button.go {
text-indent: -999em;
border: none;
background: #fff url(../images/template/btn-01.png) no-repeat;
width: 24px;
height: 24px;
margin: 0;
padding: 0;
overflow: hidden;
cursor: pointer;
}
form button.go:hover,
form button.go:active { background-position: 0 -24px; }
HTML:
<form id="fm_search" action="./" method="get">
<div>
<label class="offjs" for="fm_search-q">Search...</label>
<input id="fm_search-q" name="q" type="text" maxlength="50">
<button id="fm_search-go" class="go" name="go" type="submit">Go</button>
</div>
</form>
Note: Using JS to position label over input, so it has no affect on this demo.