Example Navigation
Example 10: Required text boxes using hidden text
Best Practice Rating: Good
The image " " out side the label.element due to visual rendering of the image after the text box, in this case the alt attribute value is set to empty, since the required information is "hidden" in the label element.
The word "required" is included as part of the label, but is hidden using CSS absolute positioning.
Note: Do not use the CSS display property with the value "none" to hide the word "require".
Using display property also hides the content from assistive technologies./li>
Example Start
Indicates required fields.
Comment required
Example End
HTML Source Code
<div class="inst">
<img src="images/required.png" alt="required imemail"/> Indicates required fields.
</div>
<div class="text">
<label for="name">Name <span class="hidden">required</span> </label>
<div><input type="text" size="30" name="name" id="name"/><img src="images/required.png" alt="" /></div>
</div>
<div class="text">
<label for="email">E-mail <span class="hidden">required</span> </label>
<div><input type="text" size="25" name="email" id="email"/><img src="images/required.png" alt="" /></div>
</div>
<div class="text">
<label for="comment">Comment <span class="hidden">required</span> <img src="images/required.png" alt="" /></label>
<textarea rows="5" cols="50" id="comment" name="comment"></textarea>
</div>
CSS Source Code
<style type="text/css">
span.hidden {
position: absolute;
top: -20em;
left: -300em;
}
div.inst {
margin: 0;
padding: 0;
margin-left: 20px;
margin-bottom: 1em;
}
div.text label {
margin: 0;
padding: 0;
margin-left: 20px;
display: block;
font-size: 100%;
}
div.text input,
div.text textarea {
margin: 0;
padding: 0;
margin-left: 20px;
margin-bottom: .5em;
font-size: 100%;
}
div.text img {
margin: 0;
padding: 0;
padding-left: .25em;
}
input:active,
input:focus,
input:hover,
textarea:active,
textarea:focus,
textarea:hover {
background-color: lightyellow;
border-color: yellow;
}
</style>