Dies funktioniert, ohne zusätzliche divs Zugabe (obwohl zugegebenermaßen es eine zusätzliche Spanne (.errorMsg
), um die Fehlermeldung enthalten:.
Mit XHTML 1.0 strict Doctype
<style>
#container
{width: 50%;
margin: 0 auto;
}
label {display: inline-block;
width: 48%;
text-align: right;
}
input {display: inline-block;
width: 50%;
}
.errorMsg
{display: block;
width: 51%;
margin: 0 0 0.5em 49%;
color: #f00;
background-color: #ffa
}
</style>
...
<div id="container">
<form>
<label for="input1">Label 1</label>
<input type="text" id="input1" name="input1" />
<span class="errorMsg">Error message</span>
<label for="input1">Label 2</label>
<input type="text" id="input2" name="input2" />
<span class="errorMsg">Error message</span>
</form>
</div>
Es ist erwähnenswert, dass die Breite des .errorMsg
51% ist, nicht 50%, um die Grenzen der Eingabe zu berücksichtigen (wird zu der 50% Breite hinzugefügt, die im CSS definiert ist. Das kann aber nur FF3.x auf Ubuntu 8.04 sein. Ich habe nicht erschöpfend getestet, oder viel, ich fürchte, YM, wie immer, MV.
Demonstration unter: http://www.davidrhysthomas.co.uk/so/errorLabels.html.
Der Bildlink ist tot, was die Frage unklar macht. –