This time I will bring you how to optimize the input box of HTML to improve user experience and ease of use. What are the things to note? Here are the ways to optimize the input box of HTML to improve user experience and ease of use. Let’s take a look at practical cases.
In order to improve user experience and ease of use, some designers will optimize things that users often use on web pages, such as input boxes. How are general input boxes optimized? From the perspective of user experience, simplifying the user steps and making it more convenient for users improves usability. For example, changing the color of the input box when the mouse is hovering over the input box, automatically selecting the default text in the input box, or clicking to enter Automatically clear the default content when the box is opened, etc.This effect sounds complicated, but it is actually very simple to do. It only takes a short piece of
javascript code to solve it. The following introduces the codes for several effects. 1. Click the Html code of the input box to select the content:
<form id="form1" name="form1" method="post" action=""> <label for="textfield">输入内容:</label> <input name="textfield" type="text" id="textfield" value="Dreamweaver"onfocus="this.select()" /> </form>
onclick to achieve the same result. Effect, such as onfocus="this.select()".
2. Change the border color or background color when the mouse is hovering over the input box
There are two methods for this effect: method one is to use the pseudo element in CSS: focus; method two is still using A short piece of javascript; The HTML code of method 1 is the same as the above example, except that the following paragraph is added to the CSS:
input:hover { border:1px solid #F00; }
<form id="form1" name="form1" method="post" action=""> <label for="textfield">输入内容:</label> <input name="textfield" type="text" id="textfield" value="Dreamweaver"onfocus="this.select()" onmouseover="this.style.borderColor='#FF6600'" onmouseout="this.style.borderColor=''" /> </form>
3. Click the input box and the default text disappears
There is another effect. When the mouse clicks on the input box, the original default text disappears. If you enter other new content and then move the mouse away, the new content of the input box remains unchanged; if you do not enter new content, the mouse leaves the input box and the default text is restored. This effect can be achieved by adding a short piece of javascript judgment:
<form id="form1" name="form1" method="post" action=""> <label for="textfield">输入内容:</label> <input name="textfield" type="text" id="textfield" value="Dreamweaver" onmouseover="this.style.borderColor='#FF6600'" onmouseout="this.style.borderColor=''" onFocus="if (value =='Dreamweaver'){value =''}" onBlur="if (value ==''){value='Dreamweaver'}"/> </form>
<input type="search" name="user_search" placeholder="Search W3School" />
How to implement an input drop-down menu in html
How to implement progressive enhancement and graceful degradation in css3 How to use the new units vw, vh, vmin, vmax of
How to use the title attribute in html Make the text
appear where the mouse is hovering
The above is the detailed content of How to optimize HTML input boxes to improve user experience and ease of use. For more information, please follow other related articles on the PHP Chinese website!