What HTML/CSS would you use to create a text input with a background?

前端 未结 7 745
甜味超标
甜味超标 2021-02-03 10:28

I have a website design that includes text input fields that look like this:

Input Field http://img401.imageshack.us/img401/4453/picture1ts2.png

I\'m wondering w

相关标签:
7条回答
  • 2021-02-03 10:58

    okoman has gotten the CSS aspect correct. May I suggest using a <label> to improve the semantic structure of the markup?

    <label id="for-field-name" for="field-name">
        <span class="label-title">Field Name <em class="required">*</em></span>
        <input id="field-name" name="field-name" type="text" class="text-input" />
    </label>
    
    <style type="text/css">
        label, span.label-title { display: block; }
    </style>
    

    Not only is this more accessible, but it provides numerous hooks that you can use for any type of DOM manipulation, validation or field-specific styling in the future.

    Edit: If you don't want the label title displayed for some reason, you can give it a class of 'accessibility' and set the class to display: none; in the CSS. This will allow screen readers to understand the input but hide it from regular users.

    0 讨论(0)
提交回复
热议问题