Disable a textbox using CSS

前端 未结 9 1203
粉色の甜心
粉色の甜心 2020-12-24 00:23

How to disable a textbox in CSS? Currently we are having a textbox in our view which can be enabled/disabled depending on a property in the model. We are having asp.net MVC

相关标签:
9条回答
  • 2020-12-24 01:01

    You can't disable a textbox in CSS. Disabling it is not a presentational task, you will have to do this in the HTML markup using the disabled attribute.

    You may be able to put something together by putting the textbox underneath an absolutely positioned transparent element with z-index... But that's just silly, plus you would need a second HTML element anyway.

    You can, however, style disabled text boxes (if that's what you mean) in CSS using

    input[disabled] { ... }
    

    from IE7 upwards and in all other major browsers.

    0 讨论(0)
  • 2020-12-24 01:03

    Just try this.

    <asp:TextBox ID="tb" onkeypress="javascript:return false;" width="50px" runat="server"></asp:TextBox>
    

    This won't allow any characters to be entered inside the TextBox.

    0 讨论(0)
  • 2020-12-24 01:13

    you can disable via css:

    pointer-events: none; 
    

    Doesn't work everywhere though.

    0 讨论(0)
提交回复
热议问题