• 회원가입
  • 로그인
  • 구글아이디로 로그인

[selector] CSS - :focus 선택자 - 포커스 된 요소 선택 (= :focus선택자 = 포커스선택자) (IE8)

목차
  1. :focus 예제 - 커서 깜빡이는 요소 선택
  2. :focus 정의
  3. :focus 구문
  4. :focus 예제 - :hover, :active, :foucs 선택자
  5. :focus 예제 - 특정 input만 적용
  6. :focus 예제 - input 포커스 시 밑줄 애니 효과
  7. :focus 예제 - input 포커스 시 너비 증가 애니 효과
 

:focus 예제 - 커서 깜빡이는 요소 선택

 
<style>
input:focus {background-color: yellow;}
</style>

<form>
<input type="text" name="focus">
<input type="submit" value="확인">
</form> 
 
※ 선택 전엔 흰색 창이다가, 커서로 선택하는 순간 input:focus 선택자에 의해 노란색 배경으로 변함.
 

:focus 정의

 
<input> 같은 요소가 선택되어 커서 깜박이는 동안의 스타일 지정.
 
 

:focus 구문

 
input:hover { CSS Style }
input 요소 위에  마우스 커서 올려놓을 때 스타일 지정.
 
input:active { CSS Style }
input 요소를  마우스로 클릭하는 순간의 스타일 지정.
※ 실제론 input:focus 스타일에 묻혀 효과 안 나타남.
 
input:focus { CSS Style }
input 요소에 커서 위치해 선택된 동안의 스타일 지정.

※ input 태그도 a 태그처럼 input:hover 와 input:active 등 선택자 사용 가능.
※ 선택자 순서는 위 순서대로 배열.
 

:focus 예제 - :hover, :active, :foucs 선택자

 
<style>
input {color:gray;}
input:hover {background-color:red;}
input:active {color:white;background-color:blue;}
input:focus {color:green;background-color:yellow;}
</style>
 
<input  type="text"/>
 
 

:focus 예제 - 특정 input만 적용

 
<style>
input.homzzang {color:gray;}
input.homzzang:hover {background-color:red;}
input.homzzang:active {color:white;background-color:blue;}
input.homzzang:focus {color:green;background-color:yellow;}
</style>
 
<input class="homzzang" type="text"/>
<input type="text"/>
 
※ 특정 input 요소에만 스타일을 주고 싶을 땐, class 선택자 이용.

 

:focus 예제 - input 포커스 시 밑줄 애니 효과

 

<style>

:focus { outline: none;}

.container { width: 200px;  position: relative;}

input[type="text"] { width: 100%;}

.input { border: 0;  padding: 10px 0; border-bottom: 1px solid #ccc;}

 

.input ~ .border {

  position: absolute;

  bottom: 0;

  left: 0;

  width: 0;

  height: 2px;

  background-color: #27ad8a;

}


.input:focus ~ .border {

  width: 100%;

  transition: 0.5s;

}

</style>

 

<div class="container">

  <input class="input" id="name" type="text" placeholder="이름 입력">

  <span class="border"></span>

</div>

<div class="container">

  <input class="input" id="nick" type="text" placeholder="닉네임 입력">

  <span class="border"></span>

</div>

 

결과보기

 

:focus 예제 - input 포커스 시 너비 증가 애니 효과

 

<style>

input {

  width: 100px;

  height: 30px;

  border-color:silver;

  outline: none;

  border-radius:5px;

  text-indent:5px;

}


input:focus {

  width: 200px;

  transition: 0.5s;

}

</style>

 

<input type="text" placeholder="검색어 입력">

 

결과보기



분류 제목
outline CSS - outline-color 속성 - 외곽선두께 (= 아웃라인컬러속성 = outline-color속성…
box CSS - width 속성 ★ - 너비 (= 가로길이 = width속성 = 위드스속성, 상속X)
box CSS - height 속성 ★ - 높이 (= 세로길이 = height속성 = 하이트속성) (※ vh, vw…
box CSS - min-width 속성 - 최소너비 (=최소가로길이 = min-width속성 = 민위드스속성)
box CSS - min-height 속성 - 최소높이 (= 최소세로길이 = min-height속성 = 민하이트속성…
box CSS - max-width 속성 - 최대너비 (= 최대가로길이 = max-width속성 = 맥스위드스속성)
box CSS - max-height 속성 - 최대높이 (= 최대세로길이 = max-height속성 = 맥스하이트속…
font CSS - font 속성 ★ - 글자스타일종합 (= font속성 = 글씨체 = 서체 = 글꼴 = 폰트속성, …
font CSS - font-size 속성 ★ - 글자크기 (= 글씨체크기= 글씨크기 = 서체크기= 글씨크기 = …
font CSS - font-family 속성 ★ - 글자종류 (= font-family속성 = 폰트패밀리속성 = 글…
font CSS - font-weight 속성 ★ - 글자굵기 (= font-weight속성 = 폰트굵기 = 글씨체굵…
font CSS - font-style 속성 - 글자기울기 (= 이텔릭체 여부 = 이탤릭 글씨체 = 글자 기울려쓰기 … 1
font CSS - font-variant 속성 - 작은 대문자 (= font-variant속성 = 폰트베리언트 = …
text CSS - color 속성 ★ - 글자색깔 (=글자색상=글자색깔=글자컬러 = 텍스트색깔 = 컬러속성 = co…
text CSS - direction 속성 - 텍스트방향 (= 텍스트진행방향 = direction속성 = 디렉션속성)…
text CSS - letter-spacing 속성 ★ - 글자 간격 사이사이 띄우기 ( 텍스트사이띄우기 = 문자 간…
text CSS - line-height 속성 ★ - 텍스트라인높이 (= line-height속성 = 텍스트줄높이 =…
text CSS - text-align 속성 ★ - 텍스트정렬 (= text-align속성 = 텍스트얼라인속성)
text CSS - text-decoration 속성 ★ - 텍스트라인 꾸미기 (= 밑줄/밑선, 가운데줄/취소선, 윗…
text CSS - text-indent 속성 ★★ - 단락 첫줄 텍스트 들여쓰기 (= text-indent속성 = …
4/25
목록
찾아주셔서 감사합니다. Since 2012