reign
reign

Reputation: 89

How to change background color of readonly textbox in css

How to change background color of readonly textbox in css

Upvotes: 3

Views: 61581

Answers (5)

Eklavya Jain
Eklavya Jain

Reputation: 47

Hi This will surely work for your code. Just try this..

<html>
  <head>
  </head>
  <body>
         <input type="text" disabled="disabled" value="JavaScript is the best" style="background-color:Black; color:green;" />
  </body>

Upvotes: 0

Rishabh Bariyar
Rishabh Bariyar

Reputation: 1

You can change the background color in css using this code but before that make sure your html page is linked with your css page.

Body {
      Background-color: red;

     }

Hope this code will work for you.

Upvotes: -2

Mark Gerryl Mirandilla
Mark Gerryl Mirandilla

Reputation: 823

you can try this

input:-moz-read-only { /* For Firefox */
    background-color: yellow;
}

input:read-only {
    background-color: yellow;
}

Upvotes: 0

olemarius
olemarius

Reputation: 1134

You could use

input[disabled="disabled"] { background:url("url-to-background-image.jpg") no-repeat #fff; }

and for older browser that doesnt support this selector, you can use jQuery to apply a class

$(document).ready(function() {
    $("input[disabled="disabled"]").addClass('disabled');
});

And unless it's disabled all the time, you should provide js for removing the class along with js for enabling it.

Upvotes: 2

jb_
jb_

Reputation: 958

There are too many unkowns in your question. Which browser do you want support? If you say textbox you seem to use ASP.NET, but there is no tag at you question.

Generally said, the behaviour between the browsers are different.

Consider the following html

<html>
      <head>
      </head>
      <body>
             <input type="text" disabled="disabled" value="This is a test" style="background-color:Black; color:Lime;" />
      </body>
</html>

IE8 renders the background color properly, but disabled controls will always have gray text with shadows. Mozille Firefox beside that renders the control correct and i am sure there will be difference all over the different browsers and even between the browser versions (IE6 would interprete the color values correctly too).

If you want to have a html regardless which browser you use, you have to use a span or other inline element, to format it with border and colors you want, instead of using a input element.

Upvotes: 7

Related Questions