css如何在文本框中设置清除按钮

发布时间:2022-03-08 13:57:02 作者:小新
来源:亿速云 阅读:307

小编给大家分享一下css如何在文本框中设置清除按钮,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

  我们先来看一下设置清除按钮具体的示例

  代码如下

  HTML代码

  <!DOCTYPEhtml>

  <html>

  <head>

  <linkhref="style.css"rel="stylesheet"type="text/css"/>

  <scripttype="text/javascript"language="javascript">

  <!--

  functionClearButton_Click(){

  this.searchForm.searchBox.value="";

  }

  -->

  </script>

  </head>

  <body>

  <formaction=""name="searchForm">

  <divclass="searchFrame">

  <inputtype="text"id="search"name="searchBox"value=""class="inputBox"/>

  <divclass="clearButton"onclick="ClearButton_Click()"></div>

  </div>

  </form>

  </body>

  </html>

  CSS代码

  style.css

  .searchFrame{

  position:relative;

  display:inline-block;

  }

  .inputBox{

  padding-right:20px;

  width:120px;

  }

  .searchFrame.clearButton{

  width:13px;

  height:13px;

  position:absolute;

  right:2px;

  top:1px;

  background:url(img/d.jpg)no-repeatleftcenter;

  cursor:pointer;

  }

  说明

  上述代码中,在文本框周围准备一个“searchFrame”框架。将清除按钮放在“searchFrame”框架的右端。通过设置样式表的正确属性将其放在右端。“searchFrame”框架被指定为“display:inline-block”,它是一个紧紧围绕文本框的框架。


看完了这篇文章,相信你对“css如何在文本框中设置清除按钮”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. css如何设置按钮样式
  2. 在文本框中设置清除按钮的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css

上一篇:css如何设置P标签内文字的字间距

下一篇:怎么用css设置删除线样式

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》