2. CSS

CSS focus-within 태그 적용하기

도피디 2024. 11. 30. 16:19
반응형

focus-within : focused인 자식을 가진 부모 엘리먼트에 적용되는 것.

 

<!DOCTYPE html>
<html lang="kr">
<head>
<title>The Nick Times</title>
<style>
body {
height: 1000vh;
margin: 50px;
}
form {
border: 1px solid salmon;
display: flex;
flex-direction: column;
padding: 20px;
}
form:focus-within {
border-color: seagreen;
}
</style>
</head>
<body>
<form>
<input type="text" name="" id="" />
<input type="text" name="" id="" />
<input type="text" name="" id="" />
</form>
</body>
</html>

 

form의 자식인 3개 input 중에

하나라도 focused 되면

border-color가 seagreen이 된다.

 

 

 

 

 

결과

 

 

 

반응형