little question

E

Eirk

Hi,
is there any way to give focus to an INPUT type=file *textfield* using
css? That is:

--->this works:


input[type="text"]:focus {
background-color: #FFCC00;
}




--->while this doesn't work:


input[type="file"]:focus {
background-color: #FFCC00;
}


Any idea?
Eirk
 
S

Steve Pugh

Eirk said:
is there any way to give focus to an INPUT type=file *textfield* using
css? That is:

--->this works:

input[type="text"]:focus {
background-color: #FFCC00;
}

Nitpick - that doesn't "give focus" to the element, it just changes
the style of the element when it recieves focus.

(And of course IE doesn't support attribute selectors or the :focus
pseudo class, but you probably know that)
--->while this doesn't work:

input[type="file"]:focus {
background-color: #FFCC00;
}

The file input is effectively unstylable. As most (but not all)
browsers display it as a combination of two widgets and as CSS
doesn't provide any way to address those two widgets independently
there's no not a lot you can do.

(Also would you want the focus state to be triggered when the focus
was on the textbox widget or the button widget or both?)

Some people go down a rather convoluted route whereby they hide the
actual <input type="file"> and instead have a standard text input and
a standard button that can be styled independently. They then use
JavaScript to pass actions and results back and forth between the
real, hidden input and the fake, visible ones.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top