I'm trying to put a element to the left of a element, however I can't seem to make them the same height and align with each other. The span always seems to be positioned a little higher.
Anyone got any ideas?
Sparkles*
Edit: HTML section
<label for="name">Username: </label>
<input type="text" name="name" id="name" value="" maxlength="15"/>
<span id="box" style="display:none"></span>
CSS
span.box{
position:absolute;
width:100px;
margin-left:20px;
border:1px;
padding:2px;
height: 16px;
}
input.name {
width: 115px;
height: 14px;
}
If you want to vertically align items in the same line, you probably don't need to make them the same height - just give them the same value for the
vertical-align
property.What a lot of people don't understand with vertical-align is that in order for things to be vertically aligned to the middle, everything in that line has to have a vertical-align property of 'middle' - not just one thing (like the span).
Imagine an invisible horizontal line running though any inline content. Usually the baseline of text, and the bottom of images, are lined up with this line. However, if you change vertical-align to middle, then the middle of the element (text span, image etc) is aligned with this line. However that's not going to line up vertically with other items if they are still aligning their bottom or baseline to that line - they would need to align their middle to that line too.
here's an slightly retouched version of SuperDucks code:
Try padding :
Keep in mind 'span' is an inline element, rather than a block level element, so size definitions don't apply, unless you use 'display:block' CSS property. Inline elements get the size of the contents, so things like font size are what define the height of that span.
Also I'd use 'label' tag with the 'for' attribute, rather than a 'span'. This makes a better structure, and has the advantage of moving the focus to the input by clicking on the label.
The following is a block-level example, which allows pixel by pixel alignment for every browser: