How Can I Style an Editable DIV to Look Like a Text Field?
Making an Editable DIV Resemble a Text Field
Oftentimes, it may be desirable to allow users to edit specific sections of a web page using editable DIVs. However, DIV elements naturally lack the visual cues that indicate editability, leaving users uncertain about whether they can interact with them.
To address this issue, CSS styling can be employed to transform an editable DIV into a semblance of a standard text input field. Fortunately, modern browsers provide specific CSS properties that mimic the appearance of native text input controls.
CSS Styling for a Text Field-Like DIV
The following CSS code can be applied to a DIV to give it a text field-like appearance:
#textarea { -moz-appearance: textfield-multiline; -webkit-appearance: textarea; border: 1px solid gray; font: medium -moz-fixed; font: -webkit-small-control; height: 28px; overflow: auto; padding: 2px; resize: both; width: 400px; }
In addition, specific styles can be applied to the textarea element for added realism:
textarea { height: 28px; width: 400px; }
CSS Styling for a Text Field-Like Input
Similarly, an input can be styled to resemble a text field using the following CSS:
#input { -moz-appearance: textfield; -webkit-appearance: textfield; background-color: white; background-color: -moz-field; border: 1px solid darkgray; box-shadow: 1px 1px 1px 0 lightgray inset; font: -moz-field; font: -webkit-small-control; margin-top: 5px; padding: 2px 3px; width: 398px; }
input { margin-top: 5px; width: 400px; }
Output
The resulting HTML and CSS produce the following output:
[Image of a textarea and an input, both styled to look like text fields]
This styling is compatible with Safari, Chrome, and Firefox, degrading gracefully for Opera and IE9.
The above is the detailed content of How Can I Style an Editable DIV to Look Like a Text Field?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

One thing that caught my eye on the list of features for Lea Verou's conic-gradient() polyfill was the last item:

Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

The inline-template directive allows us to build rich Vue components as a progressive enhancement over existing WordPress markup.

PHP templating often gets a bad rap for facilitating subpar code — but that doesn't have to be the case. Let’s look at how PHP projects can enforce a basic

Every time I start a new project, I organize the code I’m looking at into three types, or categories if you like. And I think these types can be applied to
