I am currently in the process of revamping an old HTML form to eliminate the use of tables. I found a solution on this site to give the label a fixed width, and here is how it looks in the current code:
HTML
<div id="form">
<label for="field1">Name </label>
<input type="text" id="field1" value="default name" />
</div>
CSS
label {
float: left;
width: 50px;
white-space: nowrap;
}
input {
display: block;
overflow: hidden;
width: *;
}
#field1 {
width: 150px;
}
Currently, the label is aligned at the top vertically. How can I align both the label and field vertically to the center?
Edit: Many suggestions I've received involve adjusting the position of the label by a set number of pixels. However, I want to avoid hard-coding it that way as it doesn't truly achieve vertical alignment in the middle.
Following some helpful advice from here, I have made some improvements to my code. Check out the updated code above.
I attempted using vertical-align: middle;
in label
but it didn't produce the desired result. Please keep in mind that the user will be accessing the platform through Internet Explorer.