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

[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)

분류 제목
button CSS - Button - 버튼스타일 (버튼크기, 버튼색깔, 버튼비활성화, 버튼그룹, 이미지위버튼)
position CSS - overflow 속성 ★★ - 범위이탈요소처리 (= 범위넘는요소처리 = 스크롤바 생성 = over…
font CSS - font-family 속성 ★ - 글자종류 (= font-family속성 = 폰트패밀리속성 = 글…
position CSS - position 속성 ★★★ - 위치기준대상지정 (= 위치속성 = 포지션속성 = 위치조정 = po…
selector CSS - :focus 선택자 - 포커스 된 요소 선택 (= :focus선택자 = 포커스선택자) (IE8…
intro CSS - 스타일 적용 방법 3가지 ★★★ - (인라인스타일 / 내부스타일 / 외부스타일) CSS적용순서 +…
font CSS - font-style 속성 - 글자기울기 (= 이텔릭체 여부 = 이탤릭 글씨체 = 글자 기울려쓰기 … 1
font CSS - font-size 속성 ★ - 글자크기 (= 글씨체크기= 글씨크기 = 서체크기= 글씨크기 = …
selector CSS - ID선택자, class선택자 + CSS우선순위 ★★★ (= 아이디선택자, 클래스선택자, CSS명시…
selector CSS - :first-child 가상선택자 - 그부모요소의 첫번째자식요소 (= 퍼스트차일드선택자, IE7)
selector CSS - :not(selector) 선택자 - (특정요소/특정선택자) 아닌 모든요소선택 (= not선택자 …
table CSS - border-collapse 속성★ - 테두리겹침설정 (= 테두리중첩설정 = 테두리이중방지 = b…
position CSS - float 속성 ★★★ - 요소나란히 (= 요소한줄로 = 요소가로로 = 요소옆으로 = float속…
text CSS - color 속성 ★ - 글자색깔 (=글자색상=글자색깔=글자컬러 = 텍스트색깔 = 컬러속성 = co…
1/25
목록
찾아주셔서 감사합니다. Since 2012