美文网首页
placeholder-shown妙用

placeholder-shown妙用

作者: 谁把月亮涂黑啦 | 来源:发表于2019-04-06 22:04 被阅读0次
<body>
  <div class="wrapper">
    <input type="text" class="input" placeholder="邮箱">
    <label class="label">邮箱</label>
  </div>
</body>
  .wrapper {
    width: 300px;
    margin: 100px auto;
    position: relative;
  }
  .input {
    display: inline-block;
    width: 100%;
    height: 52px;
    line-height: 1.5;
    font-size: 16px;
    color: #3a3a3a;
    padding: 8px;
    border-radius: 4px;
    outline: 0;
    border: solid 1px #ccc;
    box-sizing: border-box;
    transition: all ease 0.25s;
  }
  .input:placeholder-shown::placeholder{
    color: transparent;
  }
  .input:hover {
    border-color: #00b7ff;
  }
  .input:focus {
    box-shadow: #00b7ff 0 0 3px;
    border-color: #00b7ff;
  }
  .label {
    position: absolute;
    left: 8px;
    top: 15px;
    color: #8f8f8f;
    padding: 0 2px;
    pointer-events: none;
    background: #fff;
    transition: all ease 0.25s;
  }
  /* 输入时 placeholder 隐藏 */
  .input:not(:placeholder-shown) ~ .label,
  .input:focus ~ .label {
    color: #00b7ff;
    transform: scale(0.8) translate(0, -33px);
  }

静态图奉上,动态效果可贴代码看:


表单输入动效

相关文章

网友评论

      本文标题:placeholder-shown妙用

      本文链接:https://www.haomeiwen.com/subject/vepdiqtx.html