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

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

 

결과보기



분류 제목
color CSS - RGBA , HSL , HSLA , opacity - (색상코드)
border CSS - border-right-width 속성 - 테두리우측두께 (= 테두리우측너비 = 테두리오른쪽너비 …
transform CSS - backface-visibility 속성 - 3D요소 뒷면 노출 여부. (= backface-vi…
image CSS - Image Text - (이미지 위에 텍스트 배치/띄우기)
selector CSS - :disabled 가상선택자 - 비활성화 된 요소 선택 (= 실행불능요소 = 작동불능요소 = :d…
transform CSS - perspective-origin 속성 - 3D요소 바라보는 위치 (= perspective-or…
border CSS - border-image-repeat 속성 - 테두리 이미지 반복할지 늘릴지 선택 (= 보더이미지리…
flex CSS - flex-flow 속성(C) ☆ - (flex-direction / flex-wrap) 속성 일괄…
func CSS - clamp() 함수 - 최소값과 최대값 사이의 중간값 반환. (= clamp함수 = 클램프함수)
background CSS - background-clip 속성 - 배경영역 (= background-clip속성 = 백그라운드…
image CSS - Image Modal - (Advanced) - (이미지 모달 띄우기 효과)
border CSS - border-top-width 속성 - 테두리상단두께 (= 테두리상단너비 = border-top-…
flex CSS - flex 속성(I) ☆ - flex-grow, flex-shrink, flex-basis 속성 일…
border CSS - border-top-color 속성 - 테두리상단색상 (= 테두리상단색깔 = border-top-…
selector CSS - :nth-of-type(n) 가상선택자 - 지정타입n번째 자식요소 (순서선택자,타입선택자, IE9…
border CSS - border-left-width 속성 - 테두리좌측두께 (= 테두리좌측너비 = 테두리왼쪽너비 = …
border CSS - border-bottom-color 속성 - 테두리하단색깔 (= 보더바텀컬러속성 = border-…
flex CSS - flex-grow 속성(I) ★ - 아이템 너비 증가 (= flex-grow속성 = 플렉스그로속성…
pagination CSS - 페이징 - 기본 스타일 (Simple Pagination)
border CSS - border-left-color 속성 - 테두리좌측색상 (= 테두리좌측색깔 = 테두리왼쪽색상 = …
15/27
목록
찾아주셔서 감사합니다. Since 2012