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

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

 

결과보기


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
selector CSS - [attribute~=value] 속성선택자 - 특정 속성값단어 (단독 또는 단어앞뒤공백)인 요소…
selector CSS - [attribute|=value] 속성선택자 - 해당속성값 또는 뒤에 하이픈 연결된 속성값 보유 …
selector CSS - [attribute^=value] 속성선택자 ★ - 지정 속성값 문자열로 시작하는 요소. (=시…
selector CSS - [attribute$=value] 속성선택자 - 지정 속성값 문자열로 끝나는 요소 (IE7)
selector CSS - [attribute*=value] 속성선택자 - 지정 속성값 문자열 포함 모든 요소 (IE7)
selector CSS - :link 가상선택자 - 미방문링크 (= 링크선택자)
selector CSS - :visited 가상선택자 ★ -이미 방문한 링크 선택 (= 읽은글/방문글/확인글 표시 = 비지티…
selector CSS - :hover 가상선택자 ★ - 요소에 마우스커서위치시 효과 (= :hover선택자 = 허버선택자,…
selector CSS - :active 가상선택자 - 링크클릭순간 (= 액티브선택자, 링크선택자)
selector CSS - :focus 선택자 - 포커스 된 요소 선택 (= :focus선택자 = 포커스선택자) (IE8…
selector CSS - ::first-letter 가상선택자 - 요소의 첫번째글자 선택 (= ::first-letter선…
selector CSS - ::first-line 가상선택자 - 요소의 첫번째라인 선택 (= ::first-line선택자 =…
selector CSS - :first-child 가상선택자 - 그부모요소의 첫번째자식요소 (= 퍼스트차일드선택자, IE7)
selector CSS - ::before 가상선택자 - 요소 앞에 내용삽입 (= ::before선택자 = 비포어선택자/비…
selector CSS - ::after 가상선택자 ★ - 요소 뒤에 내용삽입 (= ::after선택자 = 에프터선택자/애프…
selector CSS - :lang(language) 가상선택자 - 특정언어속성요소 (= 언어선택자 = 랭선택자, IE8)
intro CSS - inherit (인헤리트) - 상속개념 ★
background CSS - background 속성 ★ - 배경 일괄 (= background속성 = 백그라운드속성)
background CSS - background-color 속성 ★ - 배경색깔(=배경색상=배경컬러 = background-c…
background CSS - background-image 속성 ★ - 배경이미지 (= background-image속성 = …
2/25
목록
찾아주셔서 감사합니다. Since 2012