Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    input:focus question

    I have a css page that inside I have this declared

    Code:
    input:focus, textarea:focus, select:focus{
    background:#FFFF00;
    }
    now this places a BG color of any of the fields on the form that have focus to yellow. My question is this: Is there a way to narrow down what types of input fields get the css attribute? For example I have a input type="button" on the page that I don't want to turn yellow onFocus. I only want the input type="text

    is there a way to have it do like this
    input.text:focus{background:#FFFF00;}(I know this is wrong)

    So that all text fields are yellow on focus but not buttons?

    Thank you for any help with this.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,627
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    Look up on CSS 2 selectors.
    Code:
    input[type=button]:focus {…}
    This does not work in IE 6, though (well, :focus on inputs doesn’t work in IE anyway). You could give that button an ID or class to make it backwards compatible.

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks. I was hoping to avoid going back and giving ids to all the buttons or text fields as I just wanted a single place to change the style and it update all of that type. And as of now I have many pages with many forms that I would have to change. I was hoping for just controlling a type like input, select but be able to be more specific like your example. Kind of sucks that IE does not support that.

    Thanks for your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •