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

[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="검색어 입력">

 

결과보기



분류 제목
flex CSS - flex-wrap 속성(C) ★ - 아이템 줄바꿈 가능 여부. (= flex-wrap속성 = 플렉…
text CSS - text-indent 속성 ★★ - 단락 첫줄 텍스트 들여쓰기 (= text-indent속성 = …
selector CSS - :active 가상선택자 - 링크클릭순간 (= 액티브선택자, 링크선택자)
box CSS - max-width 속성 - 최대너비 (= 최대가로길이 = max-width속성 = 맥스위드스속성)
list CSS - list-style-type 속성 ★ - 리스트 스타일 타입 (= 리스트 마커 종류 = list-…
responsive CSS - Viewport ★ - 사용자에게 보이는 웹페이지 영역 (= 메타태그 뷰포트 ※ 반응형 필수조건 …
css CSS - cursor 속성 - 커서 모양 (= cursor속성 = 커서속성)
box CSS - min-width 속성 - 최소너비 (=최소가로길이 = min-width속성 = 민위드스속성)
selector CSS - :visited 가상선택자 ★ -이미 방문한 링크 선택 (= 읽은글/방문글/확인글 표시 = 비지티…
border CSS - border-radius 속성 ★ - 테두리둥글기 지정 (= border-radius속성 = 보더…
intro CSS - inherit (인헤리트) - 상속개념 ★
flex CSS - align-items 속성(C) ★★★ - 교차축에서 아이템 정렬. (= align-items속성… 2
selector CSS - 가상선택자 중복 (= 동시, 함께, 여러개)
selector CSS - element+element 인접선택자 ★★ - 바로 뒤 인접형제요소 (요소선택자, IE7) + …
text CSS - letter-spacing 속성 ★ - 글자 간격 사이사이 띄우기 ( 텍스트사이띄우기 = 문자 간…
selector CSS - :has() 가상선택자 - 지정 요소 갖는 모든 요소 선택. (= :has선택자 = 해즈선택자)
css CSS - (div전체/TD전체/TD셀천체/LI전체)에 링크걸기 (= DIV링크/TD링크/LI링크 = 요소전…
text CSS - text-justify 속성 - 텍스트 좌우균분정렬 세부설정 (= text-justify속성 = …
text CSS - text-overflow 속성 ★ - 영역 이탈 글자 처리 (= text-overflow속성 = …
selector CSS - * 전체선택자 - 모든 요소 선택. (요소선택자군) ※ 아스테리크 (asterisk) 선택자 = …
23/27
목록
찾아주셔서 감사합니다. Since 2012