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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    50
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Drop down list text colour?

    Can I change the colour of the text in a drop down list? Or to be more precise can I change the colour of ONE of the items in the list?

    Cheers Dan.
    Last edited by DanielHowden; 11-14-2010 at 03:52 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Of course, you can. Just add an id or class to your option tag. Here let me give you an example. Then style it in your css.

    HTML and CSS:
    Code:
    <html>
    <head>
    <title></title>
    <style type="text/css">
    #red {
        color: red;
        }
    #blue {
        color: blue;
        }
    .green {
        color: green;
        }
    </style>
    </head>
    
    <body>
    <select name="country">
        <optgroup label="Africa">
            <option value="gam" id="red">Gambia</option>
            <option value="mad" id="blue">Madagascar</option>
            <option value="nam" class="green">Namibia</option>
        </optgroup>
        <optgroup label="Europe">
            <option value="fra" class="green">France</option>
            <option value="rus" class="green">Russia</option>
            <option value="uk" class="green">UK</option>
        </optgroup>
        <optgroup label="North America">
            <option value="can">Canada</option>
            <option value="mex">Mexico</option>
            <option value="usa">USA</option>
        </optgroup>
    </select>
    
    </body>
    
    </html>
    Make sure to always validate @ http://validator.w3.org/
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • Users who have thanked Chris Hick for this post:

    DanielHowden (11-14-2010)

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    50
    Thanks
    16
    Thanked 0 Times in 0 Posts
    That is awesome, thanks.

  • #4
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    You are welcome. Just remember to edit your first post and set it to resolved.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^


  •  

    Posting Permissions

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