#test label,
#test input {
position: absolute;
left: 0; top: 0;
margin: 0;
padding: 0.4em 0;
font-family: 'Helvetica', sans-serif;
font-size: 1em;
height: 2em;
border: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#test label {
background: #1265bb;
line-height: 1.15;
}
#test input {
text-indent: -1px;
opacity: 0.5;
line-height: 1.08;
}
Styling forms is a nightmare. One of the many problems is that inputs, textareas, submit buttons and labels all look different from each other, even inside a single browser. Check this example – a label and an input[type=text] with default styling overlayed on top of one another. Each has a healthy dose of underscores so you can see clearly where the baseline is, and I’ve given the input some transparency to help us:
You see the problem. The input, by default, appears to have margin space surrounding it, and depending which browser you’re in, a different font-family, font-size, padding, height and line-height than the label. Attempting to reset these in CSS gives us:
Actually, that gets pretty close. Webkit and Mozilla still offset horizontally by 1px, but we could possibly cure that with a text-indent: -1px. Try giving these some height and centring the text vertically with line-height, however, and we run into problems. FireFox does not respect line-height for inputs, so we are forced to control vertical alignment with padding:
But even here we see that in Firefox the two baselines move relative to one another when the window resizes and the text re-flows — for no real reason.
I’m convinced there are, however, some magic numbers for combinations of top and bottom padding and line-height that cause less disruption than others. And to dabble in these Dark Arts I’ve made this dynamic inputs and labels tester. Have a play around with the example at the top, using the CSS editor to restyle the test. Resort to whatever canny CSS wizadry you can muster. You can see that I’ve started with the new CSS3 box-sizing property. If you magic your way into any stable combinations that do a decent job of equalising the baseline between inputs and labels, and they work in at least FF / Webkit, post them in the comments.
I think I found a magic combo:
label, input { padding: 0.4em 0; font-size: 1em; height: 2em; box-sizing: border-box; }
label { line-height: 1.15; }
input { text-indent: -1px; line-height: 1.08; }
Doesn’t work at other font-sizes, though…
Maybe I’ve got another one…
label, input { padding: 0.5em 0 0; font-size: 1.2em; height: 2em; box-sizing: border-box; }
label { line-height: 1.04 }
input { line-height: 1.2 }
Works at all font sizes but 19px in FF, and all but 8px, 13px, 15px in Webkit:
label, input -
height: 2em
padding-top: 0.4992em (for Webkit)
padding-bottom: 0 (else clips text in FF)
label -
line-height: 1.077 (for FF)
Another reasonable compromise – god, this is a mug’s game – :
label, input –
height: 1.6em
padding-top: 0.2719em (not 10px, 13px, 15px, 16px WebKit) or 0.2493em (not 10px, 11px, 13px, 19px WebKit)
label – line-height: 1.077
A setting with content-box (all those above use border-box) model that works pretty well:
label, input -
height: 1em;
padding: 0.3327em 0;
display: inline-block;
label:
line-height: 1.064;
PillSpot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Pillspot.org. Vitamins@buy.online” rel=”nofollow”>.…
Categories: Antiviral.Skin Care.Vitamins/Herbal Supplements.Stop SmokingMens Health.Pain Relief.Mental HealthWomens Health.Antibiotics.Anxiety/Sleep Aid.Antidepressants.Blood Pressure/Heart.Anti-allergic/Asthma.Antidiabetic.Weight Loss.Stomach.Eye…
Buy:Viagra Super Force.Viagra Super Active+.Zithromax.Viagra Professional.Cialis Professional.Cialis Super Active+.Soma.Viagra.Super Active ED Pack.Cialis Soft Tabs.Cialis.Propecia.Maxaman.Tramadol.VPXL.Viagra Soft Tabs.Levitra….
Buy:Seroquel.Lipitor.Acomplia.Cozaar.Zocor.Nymphomax.Lasix.Ventolin.Female Pink Viagra.Lipothin.Advair.Buspar.Benicar.Prozac.Amoxicillin.Zetia.Female Cialis.Aricept.SleepWell.Wellbutrin SR….