开发者

How to change background color of readonly textbox in css

开发者 https://www.devze.com 2023-01-28 12:10 出处:网络
How to change backgro开发者_JS百科und color of readonly textbox in cssThere are too many unkowns in your question. Which browser do you want support? If you say textbox you seem to use ASP.NET, but th

How to change backgro开发者_JS百科und color of readonly textbox in css


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.


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.


you can try this

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

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


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消