Home > Web Front-end > CSS Tutorial > How Can I Disable or Control Resizing of Text Areas in CSS?

How Can I Disable or Control Resizing of Text Areas in CSS?

Patricia Arquette
Release: 2024-12-24 16:26:15
Original
742 people have browsed it

How Can I Disable or Control Resizing of Text Areas in CSS?

Disable Resizing of a TextArea

When working with text areas, you may encounter the need to restrict the ability of users to resize it. The default behavior allows users to adjust the height and width of the text area by clicking and dragging the bottom right corner.

To disable this resizing ability, implement the following CSS rule:

textarea {
  resize: none;
}
Copy after login

This rule will prevent users from resizing any text area element on the page. However, if you need to disable resizing for only specific text areas, you can use alternative methods:

  • Class Attribute: Use a class attribute in the HTML tag to disable resizing for a specific set of text areas.
.textarea1 {
  resize: none;
}
Copy after login
  • Name Attribute: Disable resizing for a textarea with a specific name attribute.
textarea[name=foo] {
  resize: none;
}
Copy after login
  • ID Attribute: Disable resizing for a textarea with a specific ID attribute.
#foo {
  resize: none;
}
Copy after login

In addition, you can specify the type of resizing restrictions you want to apply using the following values:

  • none (default): Disables all resizing.
  • both: Allows both horizontal and vertical resizing.
  • horizontal: Only allows horizontal resizing.
  • vertical: Only allows vertical resizing.
  • inherit: Inherits the resizing property from the parent element.

Remember that the resize property only affects the behavior of text areas when the overflow property is not set to visible (which is the default). To use the resize property, you typically need to set the overflow to scroll.

The above is the detailed content of How Can I Disable or Control Resizing of Text Areas in CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template