treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How to change bg color of 'input' text selection

  • Hi all,
    I have a problem and I hope I can find a solution here
    What i want to do is quite simple. this screenshot maybe can explain the problem better :
    http://img411.imageshack.us/img411/2100/changeo.jpg

    I want to change the background color for text selection of the input text.
    Is it possible to be done?

    I have tried the css code
    ::selection  {
    background: #ffb7b7; /* Safari */
    }
    ::-moz-selection {
    background: #ffb7b7; /* Firefox */
    }

    but no luck :(


    thanks !!
  • "virtual" said:


    heheh , i think you 've misunderstood me :p .

    Please re-read my question. I'm not looking for something fancy attribute for my form, styling, jquery-ing or something like that.
    I just want to find how, to change background color of any text selection, where the text is placed inside a input text or text area.

    Of course I have googled it before, but maybe I missed it :p . So I will really appreciate if you can show me the exact solution, url, manual etc, not just letting lmgtfy.com do that for me ;)
  • The property "background" is correct, at least that's how I've done what you're trying to do (see http://inanindeterminateplace.com/contact/ for an example).

    That said, what is the :: doing there? Could that be the problem?
  • "Nipperkin" said:
    The property "background" is correct, at least that's how I've done what you're trying to do (see http://inanindeterminateplace.com/contact/ for an example).

    That said, what is the :: doing there? Could that be the problem?


    thank you for your reply;)

    please see the screenshot of your contact form :
    http://img23.imageshack.us/img23/9000/bluebg.png

    I want to change the bacground color of selexted text "Lorem ipsum bla bla"
    Hope you can see what I mean :)
  • Sorry, I didn't read you closely enough (:oops: ) and don't have a solution. I sniffed around a bit and found many pages on changing text selection colors giving the code you tried, but none on changing selection colors in input fields...
  • Well unless I am misunderstanding you again, how about this
    http://www.cssplay.co.uk/menu/form.html
    No.1 CSS Play has a background image in the input boxes and No. 5 changes on hover.
  • Just to make sure everyone is on the same page, the OP is referring to this:

    http://css-tricks.com/overriding-the-de ... -with-css/
  • Aha :o, that 's why I was being so thick...
  • thank you all for the helps, i really appreciate it ;)

    "virtual" said:
    Well unless I am misunderstanding you again, how about this
    http://www.cssplay.co.uk/menu/form.html
    No.1 CSS Play has a background image in the input boxes and No. 5 changes on hover.


    sorry, it doesn't work virtual. It just changing the input background, not the selection colors

    "TheDoc" said:
    Just to make sure everyone is on the same page, the OP is referring to this:

    http://css-tricks.com/overriding-the-de ... -with-css/


    Yes, it's working good with p, div etc, but not with the selection color of input fields.

    Please see the image below :
    http://img132.imageshack.us/img132/125/ikoko.png

    this is my styling code :
    <style>
    ::selection {
    background: #cc0000; /* Safari */
    }
    ::-moz-selection {
    background: #cc0000; /* Firefox */
    }
    input.changeselection::-moz-selection {
    background: #cc0000;
    }

    input.changeselection::selection {
    background: #cc0000;
    }

    </style>

    It wrks properly with the <p> and other html element, but not with the input field / text area
  • I don't think you actually can. If you look at CSS-Tricks, you'll see that all of the input areas use a standard blue.
  • "TheDoc" said:
    I don't think you actually can. If you look at CSS-Tricks, you'll see that all of the input areas use a standard blue.

    Yup I see. How about using javascript. Is it possible?

    thanks
  • You are forgetting the color!


    ::selection {
    background:#FFFFFF;
    color:#000000;
    }
    ::-moz-selection {
    background:#FFFFFF;
    color:#000000;
    }
    ::-webkit-selection {
    background:#FFFFFF;
    color:#000000;
    }