The form Placeholder uses IconFont text
The problem
Recently I was writing a background login page and had the idea of adding a Font awesome icon to the placeholder of the account password entry field. (as shown in figure)
But the placeholder text is defined in the placeholder=”” property. Font awesome is implemented with the
<input type="text" class="text" placeholder="Username">
<i class="fa fa-user"></i>
Copy the code
The solution
I did some research and found ali’s IconFont, also an IconFont frame. Unlike font-awesome, IconFont offers a variety of references. Here we insert the icon text into the form placeholder via a Unicode reference.
- First we select a few ICONS to add to our own project. It is also worth mentioning in the icon library
Font-awesome
Icon. - Generate the project, download the file.
- Place the downloaded files in the site directory.
- In the CSS
font-face
andThe style of the iconfont
. - Then, in
placeholder
Insert the corresponding icon into the value ofunicode
Can.
<input type="text" class="text" placeholder=" The user name">
Copy the code
conclusion
Finally, I summarize the advantages of IconFont:
- There are several ways to introduce icon fonts for different situations.
- The icon library is rich, and you can edit the icon twice, or upload your own design icon.
- Instead of importing the entire icon library, you simply add the icon file from your own project. Save space and speed up loading.
- Support domestic production.