已合作成功的客户

遍及全国及海外

中国

杭州,绍兴,宁波,湖州,嘉兴,温州,台州,上海,北京,南京,苏州,常州,无锡,长沙,青岛,江西,台湾,南宁,海南,成都,哈尔滨,深圳,香港,沈阳 ...

海外

美国,加拿大,丹麦,澳大利亚,新加坡,法国,智利,日本,英国 ...

合作咨询

4001-355-360

洞见

news

洞察行业新闻,实时了解最新动态

placeholder-shown 配合 focus-within 实现 input 输入交互

作者:admin

来源:lanyunwork

时间:2025-12-23

分享到:

使用 :placeholder-shown && :focus-within 实现 input 输入交互。

 

HTML:

<div class="g-container">
  <input type="text" placeholder="输入你想查询的内容" class="g_input_search" >
  <button type="button" class="g_button_search">GO</button>
</div>

SCSS:

.g-container {
  position: relative;
  margin: 100px auto;
  display: flex;
  flex-wrap: wrap;
  width: 500px;
  height: 60px;
  overflow: hidden;
  transition: 0.3s;

  & > * {
      border: none;
      outline: none;
  }

  .g_input_search {
      padding: 0 15px;
      height: 100%;
      width: 100%;
      border: 1px solid #ddd;
      font-size: 18px;
      box-sizing: border-box;

      &:not(:placeholder-shown) {
          border: 1px solid #03a9f4;
           
          + .g_button_search {
              opacity: 1;
          }
      }

      &:placeholder-shown {
           
          + .g_button_search {
              opacity: 0;
          }
      }
  }

  .g_button_search {
      background: #03a9f4;
      color: #feffd4;
      font-size: 15px;
      cursor: pointer;
      width: 100px;
      height: calc(100% - 20px);
      transition: 0.3s;
      position: absolute;
      right: 10px;
      top: 10px;
  }
   
  &:focus-within {
      transform: translateY(-4px);
      border-color: #bbb;
      box-shadow: 4px 4px 10px 2px #ddd;
  }
}

具体效果:

默认状态:

点击状态:

输入文本状态:

 

业务咨询

微信咨询

请扫二维码
咨询项目经理

400电话

4001-355-360

获取方案

与蓝韵项目经理通话

请输入正确的手机号码格式

信息保护中请放心填写

在线咨询
 
提交成功
关闭浮窗