Try this CSS table layout (no markup changes). Set the container div
as table
, and two inner div
s as table-row
, and label
+ textarea
as table-cell
, with some other CSS adjustments, see the comments in the code snippet.
.credentials {
display: table;
width: 100%;
background: black;
border-collapse: separate;
border-spacing: 10px; /*for spacing*/
}
.username, .key {
display: table-row;
}
label, textarea {
display: table-cell;
vertical-align: middle; /*or top/bottom*/
}
label {
width: 1%; /*small value*/
white-space: nowrap; /*prevent wrapping*/
color: white;
}
<div class="credentials">
<div class="username">
<label>Username:</label>
<textarea></textarea>
</div>
<div class="key">
<label>Activation key:</label>
<textarea></textarea>
</div>
</div>
Edit: as one of the comment below pointed out using <input>
elements rather than <textarea>
, and I think that makes sense. See the updated code snippet.
.credentials {
display: table;
width: 100%;
background: black;
border-collapse: separate;
border-spacing: 10px; /*for spacing*/
}
.credentials .username,
.credentials .key {
display: table-row;
}
.credentials label,
.credentials input[type="text"],
.credentials input[type="password"]{
display: table-cell;
vertical-align: middle;
padding: 4px;
}
.credentials label {
width: 1%; /*small value*/
white-space: nowrap; /*prevent wrapping*/
color: white;
}
<div class="credentials">
<div class="username">
<label>Username:</label>
<input type="text">
</div>
<div class="key">
<label>Activation key:</label>
<input type="password">
</div>
</div>