css实现表单输入框标签聚焦上移动画效果代码

代码语言:html

所属分类:表单美化

代码描述:css实现表单输入框标签聚焦上移动画效果代码

代码标签: css 输入框 标签 聚焦 上移 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  
  
<style>
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  padding: 20px;
  font-size: 20px;
  background: #f3f4f6;
}

@media (min-width: 600px) {
  body {
    padding: 40px;
  }
}
.input-wrapper {
  position: relative;
  margin-top: 30px;
  margin-inline: auto;
  max-width: 400px;
}

.input {
  font-size: 20px;
  width: 100%;
  padding: 8px 0;
  padding-right: 30px;
  color: #333;
  border: none;
  border-bottom: 1px solid #ddd;
  transition: border-color 250ms;
  background-color: transparent;
}
.input:focus {
  outline: none;
  border-bottom-color: #777;
}
.input::placeholder {
  color: transparent;
}
.input::-webkit-contacts-auto-fill-button {
  visibility: hidden;
  pointer-events: none;
  position: absolute;
}

.label {
  position: absolute;
  top: 8px;
  left: 0;
  color: #43454e;
  pointer-events: none;
  transform-origin: left center;
  transition: transform 250ms;
  font-family: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif;
}

.input:focus + .label,
.input:not(:placeholder-shown) + .label {
  transform: translateY(-100%) scale(0.75);
}

.clear {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  top: 50%;
  right: -9px;
  transform: translateY(-50%);
  background: none;
  border: none;
  border-radius: 50%;
  height: 30px;
  width: 30px;
  color: #777;
  transition: color 250ms;
  display: flex;
  align-items: center;
  justify-content: center;
}
.clear:hover, .clear:focus {
  color: #333;
}

.input:placeholder-shown + .label + .clear {
  display: none;
}
</style>

  
</head>

<body >.........完整代码请登录后点击上方下载按钮下载查看

网友评论0