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

前端 未结 7 829
甜味超标
甜味超标 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:43

    I'd do it this way:

    
    

    You just have to adjust the padding values so everything fits correctly. It is - in my eyes- definitely the best solution since in any other case you're working with a whole input field. And the whole input field is - by definition - a box where users can enter text.

    If you can rely on JavaScript you could wrap such div-Elements around your input fields programatically.

    Edit: With jQuery you could do it this way:

    $( 'input.custom' ).wrap( '
    ' );

    CSS:

    div.custom {
        background:url(/images/input-bkg-w173.gif) no-repeat;
        padding:8px 5px 4px 5px;
    }
    input.custom {
        background-color: #fff;
        border:none;
        font-size:10px;
    }
    

    And your HTML:

    
    

提交回复
热议问题