[前端] html中input提示文字样式修改的示例代码

2568 0
王子 2022-10-19 15:45:47 | 显示全部楼层 |阅读模式
在很多网站上我们都看到input输入框显示提示文字,让我们一起来看看如果在input输入框中显示提示文字。我们只需要在<input>标签里添加:placeholder="提示文字即可",那么如果要修改提示文字的样式呢?可以这样设置css样式:
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>input输入框提示文字</title>
  6. <style>
  7. /*修改提示文字的颜色*/
  8. input::-webkit-input-placeholder { /* WebKit browsers */
  9. color: red;
  10. }
  11. input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
  12. color: red;
  13. }
  14. input::-moz-placeholder { /* Mozilla Firefox 19+ */
  15. color: red;
  16. }
  17. input:-ms-input-placeholder { /* Internet Explorer 10+ */
  18. color: red;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <input type="text" placeholder="请输入用户名" />
  24. </body>
  25. </html>
复制代码
修改后提示文字样式如下:


PS:下面看下HTML5里的input标签的required属性提示文字修改
在做表单提交时我们有时会遇到这样的需求,在用户没有输入必填信息点提交时提示文字需要改为我们想要的提示信息,那么可以在input里面增加这样的语句:
  1. <input type="text" placeholder="您的姓名" required oninvalid="setCustomValidity('请输入您的姓名');" oninput="setCustomValidity('');" />
复制代码
到此这篇关于html中input提示文字样式修改的文章就介绍到这了,更多相关html input 文字样式内容请搜索中国红客联盟以前的文章或继续浏览下面的相关文章,希望大家以后多多支持中国红客联盟!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行