Home  >  Article  >  Web Front-end  >  How to set the input box to be non-editable in css

How to set the input box to be non-editable in css

藏色散人
藏色散人Original
2021-02-02 10:07:085091browse

How to set the input box to be non-editable in css: first create an HTML sample file; then define an input tag; then add the css style "pointer-events: none;" to the input.

How to set the input box to be non-editable in css

The operating environment of this article: windows7 system, HTML5&&CSS3 version, Dell G3 computer.

css makes input uneditable

Add css style pointer-events: none; to the input

input{
    pointer-events: none;
}

Use pointer-events to prevent An element being the target of a mouse event does not necessarily mean that the event listener on the element will never fire. If an element descendant explicitly specifies the pointer-events attribute and allows it to be the target of mouse events, then any events pointed to that element will propagate through the parent element during event propagation and trigger the event listeners on it in the appropriate manner. . Of course, mouse activity on the screen that is on the parent element but not on the descendant element will not be captured by the parent element and descendant elements (will pass through the parent element and point to the element located below it).

Make input uneditable in HTML

1. Add the disabled attribute to the input tag

The disabled attribute stipulates that the input element should be disabled. The disabled input element cannot be edited or disabled. Copy, cannot be selected, cannot receive focus, and the value will not be received in the background. After setting, the color of the text will turn gray. The disabled attribute cannot be used with 10a0c4c6fe334f1dd2642c4aa224944a.

Example:

<input type="text" disabled="disabled" />

2. Add the readonly attribute to the input tag

The readonly attribute specifies that the input field is read-only and copyable. However, the user can use the Tab key to switch to the A field is selectable, can receive focus, and its text can be selected or copied. The passed value will be received in the background. The readonly attribute prevents users from modifying the value.

The readonly attribute can be used with 23efcc05e98690ceeb219581933e4231 or 794332e4da1b97221ff0ba8bc66903c4.

Example:

<input type="text" readonly="readonly">

Recommended: "css video tutorial"

The above is the detailed content of How to set the input box to be non-editable in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn