비전공자 개발일기

CSS Input Text Field Animation 본문

HTML _CSS

CSS Input Text Field Animation

HiroDaegu 2022. 6. 14. 00:22
728x90
SMALL

 

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS INPUT FIELD TEXT ANIMATION</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="inputBox">
    <input type="text" required="required">
    <span>First Name</span>
  </div>
  <div class="inputBox">
    <input type="text" required="required">
    <span>Last Name</span>
  </div>
</body>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  flex-direction: column;
  gap: 30px;
  background-color: #1D2B3A;
}

.inputBox {
  position: relative;
  width: 250px;
}

.inputBox input {
  width: 100%;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .25);
  background-color: #1D2B3A;
  border-radius: 5px;
  outline: none;
  color: #FFF;
  font-size: 1em;
  transition: .5s;
}

.inputBox span {
  position: absolute;
  left: 0;
  padding: 10px;
  pointer-events: none;
  font-size: 1em;
  color: rgba(255, 255, 255, .25);
  text-transform: uppercase;
  transition: .5s;
}

.inputBox input:valid ~ span, 
.inputBox input:focus ~ span {
  color: #00DFC4;
  transform: translate(10px, -7px);
  font-size: .65em;
  padding: 0 10px;
  background-color: #1D2B3A;
  border-left: 1px solid #00DFC4;
  border-right: 1px solid #00DFC4;
  letter-spacing: .2em;
}

.inputBox:nth-child(2) input:valid ~ span, 
.inputBox:nth-child(2) input:focus ~ span {
  background-color: #00DFC4;
  color: #1D2B3A;
  border-radius: 2px;
} 

.inputBox input:valid, 
.inputBox input:focus {
  border: 1px solid #00DFC4;
}
728x90
LIST

'HTML _CSS' 카테고리의 다른 글

Scroll Animation  (0) 2022.06.17
Mobile Battery percentage Check  (0) 2022.06.16
Reavl Text Animation  (0) 2022.06.13
Emoji Animation  (0) 2022.06.12
Heartbeat Loading Animation  (0) 2022.06.11